Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internationalization / Localization #647

Merged
merged 2 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"scribe::auth.instruction.query": "To authenticate requests, include a query parameter **`:parameterName`** in the request.",
"scribe::auth.instruction.body": "To authenticate requests, include a parameter **`:parameterName`** in the body of the request.",
"scribe::auth.instruction.query_or_body": "To authenticate requests, include a parameter **`:parameterName`** either in the query string or in the request body.",
"scribe::auth.instruction.bearer": "To authenticate requests, include an **`Authorization`** header with the value **`\"Bearer :placeholder\"`**.",
"scribe::auth.instruction.basic": "To authenticate requests, include an **`Authorization`** header in the form **`\"Basic {credentials}\"`**. The value of `{credentials}` should be your username/id and your password, joined with a colon (:), and then base64-encoded.",
"scribe::auth.instruction.header": "To authenticate requests, include a **`:parameterName`** header with the value **`\":placeholder\"`**.",
"scribe::auth.details": "All authenticated endpoints are marked with a `requires authentication` badge in the documentation below.",
"scribe::search": "Search",
"scribe::base_url": "Base URL",
"scribe::headers.introduction": "Introduction",
"scribe::headers.auth": "Authenticating requests",
"scribe::no_auth": "This API is not authenticated.",
"scribe::example_request": "Example request",
"scribe::example_response": "Example response",
"scribe::example_response.binary": "Binary data",
"scribe::example_response.empty": "Empty response",
"scribe::endpoint.request": "Request",
"scribe::endpoint.headers": "Headers",
"scribe::endpoint.url_parameters": "URL Parameters",
"scribe::endpoint.body_parameters": "Body Parameters",
"scribe::endpoint.query_parameters": "Query Parameters",
"scribe::endpoint.response": "Response",
"scribe::endpoint.response_fields": "Response Fields",
"scribe::try_it_out.open": "Try it out ⚡",
"scribe::try_it_out.cancel": "Cancel 🛑",
"scribe::try_it_out.send": "Send Request 💥",
"scribe::try_it_out.loading": "⏱ Sending...",
"scribe::try_it_out.received_response": "Received response",
"scribe::try_it_out.request_failed": "Request failed with error",
"scribe::try_it_out.error_help": "Tip: Check that you're properly connected to the network.\nIf you're a maintainer of ths API, verify that your API is running and you've enabled CORS.\nYou can check the Dev Tools console for debugging information.",
"scribe::links.postman": "View Postman collection",
"scribe::links.openapi": "View OpenAPI spec"
}
23 changes: 12 additions & 11 deletions resources/js/tryitout.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ function getCookie(name) {

function tryItOut(endpointId) {
document.querySelector(`#btn-tryout-${endpointId}`).hidden = true;
document.querySelector(`#btn-executetryout-${endpointId}`).hidden = false;
document.querySelector(`#btn-canceltryout-${endpointId}`).hidden = false;
const executeBtn = document.querySelector(`#btn-executetryout-${endpointId}`).hidden = false;
executeBtn.disabled = false;

// Show all input fields
document.querySelectorAll(`input[data-endpoint=${endpointId}],label[data-endpoint=${endpointId}]`)
Expand All @@ -63,7 +64,7 @@ function cancelTryOut(endpointId) {
document.querySelector(`#btn-tryout-${endpointId}`).hidden = false;
const executeBtn = document.querySelector(`#btn-executetryout-${endpointId}`);
executeBtn.hidden = true;
executeBtn.textContent = "Send Request 💥";
executeBtn.textContent = executeBtn.dataset.initialText;
document.querySelector(`#btn-canceltryout-${endpointId}`).hidden = true;
// Hide inputs
document.querySelectorAll(`input[data-endpoint=${endpointId}],label[data-endpoint=${endpointId}]`)
Expand All @@ -88,7 +89,7 @@ function makeAPICall(method, path, body = {}, query = {}, headers = {}, endpoint
body = JSON.stringify(body)
}

const url = new URL(window.baseUrl + '/' + path.replace(/^\//, ''));
const url = new URL(window.tryItOutBaseUrl + '/' + path.replace(/^\//, ''));

// We need this function because if you try to set an array or object directly to a URLSearchParams object,
// you'll get [object Object] or the array.toString()
Expand Down Expand Up @@ -118,7 +119,7 @@ function makeAPICall(method, path, body = {}, query = {}, headers = {}, endpoint
headers,
body: method === 'GET' ? undefined : body,
signal: window.abortControllers[endpointId].signal,
referrer: window.baseUrl,
referrer: window.tryItOutBaseUrl,
mode: 'cors',
credentials: 'same-origin',
})
Expand Down Expand Up @@ -149,7 +150,7 @@ function handleResponse(endpointId, response, status, headers) {
} catch (e) {

}
responseContentEl.textContent = response === '' ? '<Empty response>' : response;
responseContentEl.textContent = response === '' ? responseContentEl.dataset.emptyResponseText : response;
isJson && window.hljs.highlightElement(responseContentEl);
const statusEl = document.querySelector('#execution-response-status-' + endpointId);
statusEl.textContent = ` (${status})`;
Expand All @@ -164,10 +165,8 @@ function handleError(endpointId, err) {

// Show error views
let errorMessage = err.message || err;
errorMessage += "\n\nTip: Check that you're properly connected to the network.";
errorMessage += "\nIf you're a maintainer of ths API, verify that your API is running and you've enabled CORS.";
errorMessage += "\nYou can check the Dev Tools console for debugging information.";
document.querySelector('#execution-error-message-' + endpointId).textContent = errorMessage;
const $errorMessageEl = document.querySelector('#execution-error-message-' + endpointId);
$errorMessageEl.textContent = errorMessage + $errorMessageEl.textContent;
const errorEl = document.querySelector('#execution-error-' + endpointId);
errorEl.hidden = false;
errorEl.scrollIntoView({behavior: "smooth", block: "center"});
Expand All @@ -176,7 +175,8 @@ function handleError(endpointId, err) {

async function executeTryOut(endpointId, form) {
const executeBtn = document.querySelector(`#btn-executetryout-${endpointId}`);
executeBtn.textContent = "⏱ Sending...";
executeBtn.textContent = executeBtn.dataset.loadingText;
executeBtn.disabled = true;
executeBtn.scrollIntoView({behavior: "smooth", block: "center"});

let body;
Expand Down Expand Up @@ -266,6 +266,7 @@ async function executeTryOut(endpointId, form) {
handleError(endpointId, err);
})
.finally(() => {
executeBtn.textContent = "Send Request 💥";
executeBtn.disabled = false;
executeBtn.textContent = executeBtn.dataset.initialText;
});
}
4 changes: 2 additions & 2 deletions resources/views/markdown/auth.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Authenticating requests
# {{ __("scribe::headers.auth") }}

@if(!$isAuthed)
This API is not authenticated.
{!! __("scribe::no_auth") !!}
@else
{!! $authDescription !!}

Expand Down
4 changes: 2 additions & 2 deletions resources/views/markdown/intro.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Introduction
# {{ __("scribe::headers.introduction") }}

{!! $description !!}

<aside>
<strong>Base URL</strong>: <code>{!! $baseUrl !!}</code>
<strong>{{ __("scribe::base_url") }}</strong>: <code>{!! $baseUrl !!}</code>
</aside>

{!! $introText !!}
Expand Down
40 changes: 22 additions & 18 deletions resources/views/themes/default/endpoint.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{!! Parsedown::instance()->text($endpoint->metadata->description ?: '') !!}

<span id="example-requests-{!! $endpoint->endpointId() !!}">
<blockquote>Example request:</blockquote>
<blockquote>{{ __("scribe::example_request") }}:</blockquote>

@foreach($metadata['example_languages'] as $language)

Expand All @@ -27,7 +27,7 @@
@if($endpoint->isGet() || $endpoint->hasResponses())
@foreach($endpoint->responses as $response)
<blockquote>
<p>Example response ({{ $response->fullDescription() }}):</p>
<p>{{ __("scribe::example_response") }} ({{ $response->fullDescription() }}):</p>
</blockquote>
@if(count($response->headers))
<details class="annotation">
Expand All @@ -39,9 +39,9 @@
@endforeach </code></pre></details> @endif
<pre>
@if(is_string($response->content) && Str::startsWith($response->content, "<<binary>>"))
<code>[Binary data] - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}</code>
<code>{!! __("scribe::example_response.binary") !!} - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}</code>
@elseif($response->status == 204)
<code>[Empty response]</code>
<code>{!! __("scribe::example_response.empty") !!}</code>
@else
@php($parsed = json_decode($response->content))
{{-- If response is a JSON string, prettify it. Otherwise, just print it --}}
Expand All @@ -51,14 +51,15 @@
@endif
</span>
<span id="execution-results-{{ $endpoint->endpointId() }}" hidden>
<blockquote>Received response<span
<blockquote>{{ __("scribe::try_it_out.received_response") }}<span
id="execution-response-status-{{ $endpoint->endpointId() }}"></span>:
</blockquote>
<pre class="json"><code id="execution-response-content-{{ $endpoint->endpointId() }}" style="max-height: 400px;"></code></pre>
<pre class="json"><code id="execution-response-content-{{ $endpoint->endpointId() }}"
data-empty-response-text="<{{ __("scribe::example_response.empty") }}>" style="max-height: 400px;"></code></pre>
</span>
<span id="execution-error-{{ $endpoint->endpointId() }}" hidden>
<blockquote>Request failed with error:</blockquote>
<pre><code id="execution-error-message-{{ $endpoint->endpointId() }}"></code></pre>
<blockquote>{{ __("scribe::try_it_out.request_failed") }}:</blockquote>
<pre><code id="execution-error-message-{{ $endpoint->endpointId() }}">{{ "\n\n".__("scribe::try_it_out.error_help") }}</code></pre>
</span>
<form id="form-{{ $endpoint->endpointId() }}" data-method="{{ $endpoint->httpMethods[0] }}"
data-path="{{ $endpoint->uri }}"
Expand All @@ -68,21 +69,24 @@
autocomplete="off"
onsubmit="event.preventDefault(); executeTryOut('{{ $endpoint->endpointId() }}', this);">
<h3>
Request&nbsp;&nbsp;&nbsp;
{{ __("scribe::endpoint.request") }}&nbsp;&nbsp;&nbsp;
@if($metadata['try_it_out']['enabled'] ?? false)
<button type="button"
style="background-color: #8fbcd4; padding: 5px 10px; border-radius: 5px; border-width: thin;"
id="btn-tryout-{{ $endpoint->endpointId() }}"
onclick="tryItOut('{{ $endpoint->endpointId() }}');">Try it out ⚡
onclick="tryItOut('{{ $endpoint->endpointId() }}');">{{ __("scribe::try_it_out.open") }}
</button>
<button type="button"
style="background-color: #c97a7e; padding: 5px 10px; border-radius: 5px; border-width: thin;"
id="btn-canceltryout-{{ $endpoint->endpointId() }}"
onclick="cancelTryOut('{{ $endpoint->endpointId() }}');" hidden>Cancel 🛑
onclick="cancelTryOut('{{ $endpoint->endpointId() }}');" hidden>{{ __("scribe::try_it_out.cancel") }}
</button>&nbsp;&nbsp;
<button type="submit"
style="background-color: #6ac174; padding: 5px 10px; border-radius: 5px; border-width: thin;"
id="btn-executetryout-{{ $endpoint->endpointId() }}" hidden>Send Request 💥
id="btn-executetryout-{{ $endpoint->endpointId() }}"
data-initial-text="{{ __("scribe::try_it_out.send") }}"
data-loading-text="{{ __("scribe::try_it_out.loading") }}"
hidden>{{ __("scribe::try_it_out.send") }}
</button>
@endif
</h3>
Expand All @@ -93,7 +97,7 @@
</p>
@endforeach
@if(count($endpoint->headers))
<h4 class="fancy-heading-panel"><b>Headers</b></h4>
<h4 class="fancy-heading-panel"><b>{{ __("scribe::endpoint.headers") }}</b></h4>
@foreach($endpoint->headers as $name => $example)
<?php
$htmlOptions = [];
Expand All @@ -118,7 +122,7 @@
@endforeach
@endif
@if(count($endpoint->urlParameters))
<h4 class="fancy-heading-panel"><b>URL Parameters</b></h4>
<h4 class="fancy-heading-panel"><b>{{ __("scribe::endpoint.url_parameters") }}</b></h4>
@foreach($endpoint->urlParameters as $attribute => $parameter)
<div style="padding-left: 28px; clear: unset;">
@component('scribe::components.field-details', [
Expand All @@ -136,7 +140,7 @@
@endforeach
@endif
@if(count($endpoint->queryParameters))
<h4 class="fancy-heading-panel"><b>Query Parameters</b></h4>
<h4 class="fancy-heading-panel"><b>{{ __("scribe::endpoint.query_parameters") }}</b></h4>
@foreach($endpoint->queryParameters as $attribute => $parameter)
<?php
$htmlOptions = [];
Expand All @@ -161,16 +165,16 @@
@endforeach
@endif
@if(count($endpoint->nestedBodyParameters))
<h4 class="fancy-heading-panel"><b>Body Parameters</b></h4>
<h4 class="fancy-heading-panel"><b>{{ __("scribe::endpoint.body_parameters") }}</b></h4>
<x-scribe::nested-fields
:fields="$endpoint->nestedBodyParameters" :endpointId="$endpoint->endpointId()"
/>
@endif
</form>

@if(count($endpoint->responseFields))
<h3>Response</h3>
<h4 class="fancy-heading-panel"><b>Response Fields</b></h4>
<h3>{{ __("scribe::endpoint.response") }}</h3>
<h4 class="fancy-heading-panel"><b>{{ __("scribe::endpoint.response_fields") }}</b></h4>
<x-scribe::nested-fields
:fields="$endpoint->nestedResponseFields" :endpointId="$endpoint->endpointId()"
:isInput="false"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/themes/default/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

@if($tryItOut['enabled'] ?? true)
<script>
var baseUrl = "{{ $tryItOut['base_url'] ?? config('app.url') }}";
var tryItOutBaseUrl = "{{ $tryItOut['base_url'] ?? config('app.url') }}";
var useCsrf = Boolean({{ $tryItOut['use_csrf'] ?? null }});
var csrfUrl = "{{ $tryItOut['csrf_url'] ?? null }}";
</script>
Expand Down
6 changes: 3 additions & 3 deletions resources/views/themes/default/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@endisset

<div class="search">
<input type="text" class="search" id="input-search" placeholder="Search">
<input type="text" class="search" id="input-search" placeholder="{{ __("scribe::search") }}">
</div>

<div id="toc">
Expand Down Expand Up @@ -52,10 +52,10 @@

<ul class="toc-footer" id="toc-footer">
@if($metadata['postman_collection_url'])
<li style="padding-bottom: 5px;"><a href="{!! $metadata['postman_collection_url'] !!}">View Postman collection</a></li>
<li style="padding-bottom: 5px;"><a href="{!! $metadata['postman_collection_url'] !!}">{!! __("scribe::links.postman") !!}</a></li>
@endif
@if($metadata['openapi_spec_url'])
<li style="padding-bottom: 5px;"><a href="{!! $metadata['openapi_spec_url'] !!}">View OpenAPI spec</a></li>
<li style="padding-bottom: 5px;"><a href="{!! $metadata['openapi_spec_url'] !!}">{!! __("scribe::links.openapi") !!}</a></li>
@endif
<li><a href="http://github.com/knuckleswtf/scribe">Documentation powered by Scribe ✍</a></li>
</ul>
Expand Down
Loading