Skip to content

Commit

Permalink
Internationalization: Extract strings
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Apr 21, 2023
1 parent fbe609c commit 4fd2a26
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 65 deletions.
32 changes: 32 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"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.received_response": "Received response",
"scribe::try_it_out.request_failed": "Request failed with error",
"scribe::links.postman": "View Postman collection",
"scribe::links.openapi": "View OpenAPI spec"
}
5 changes: 4 additions & 1 deletion 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 Down Expand Up @@ -177,6 +178,7 @@ function handleError(endpointId, err) {
async function executeTryOut(endpointId, form) {
const executeBtn = document.querySelector(`#btn-executetryout-${endpointId}`);
executeBtn.textContent = "⏱ Sending...";
executeBtn.disabled = true;
executeBtn.scrollIntoView({behavior: "smooth", block: "center"});

let body;
Expand Down Expand Up @@ -266,6 +268,7 @@ async function executeTryOut(endpointId, form) {
handleError(endpointId, err);
})
.finally(() => {
executeBtn.disabled = false;
executeBtn.textContent = "Send Request 💥";
});
}
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
32 changes: 16 additions & 16 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,13 +51,13 @@
@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>
</span>
<span id="execution-error-{{ $endpoint->endpointId() }}" hidden>
<blockquote>Request failed with error:</blockquote>
<blockquote>{{ __("scribe::try_it_out.request_failed") }}:</blockquote>
<pre><code id="execution-error-message-{{ $endpoint->endpointId() }}"></code></pre>
</span>
<form id="form-{{ $endpoint->endpointId() }}" data-method="{{ $endpoint->httpMethods[0] }}"
Expand All @@ -68,21 +68,21 @@
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() }}" hidden>{{ __("scribe::try_it_out.send") }}
</button>
@endif
</h3>
Expand All @@ -93,7 +93,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 +118,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 +136,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 +161,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
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
18 changes: 9 additions & 9 deletions resources/views/themes/elements/endpoint.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
@if(count($endpoint->headers))
<div class="sl-stack sl-stack--vertical sl-stack--5 sl-flex sl-flex-col sl-items-stretch">
<h3 class="sl-text-2xl sl-leading-snug sl-font-prose">
Headers
{{ __("scribe::endpoint.headers") }}
</h3>
<div class="sl-text-sm">
@foreach($endpoint->headers as $header => $value)
Expand All @@ -70,7 +70,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }

@if(count($endpoint->urlParameters))
<div class="sl-stack sl-stack--vertical sl-stack--6 sl-flex sl-flex-col sl-items-stretch">
<h3 class="sl-text-2xl sl-leading-snug sl-font-prose">URL Parameters</h3>
<h3 class="sl-text-2xl sl-leading-snug sl-font-prose">{{ __("scribe::endpoint.url_parameters") }}</h3>

<div class="sl-text-sm">
@foreach($endpoint->urlParameters as $attribute => $parameter)
Expand All @@ -93,7 +93,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }

@if(count($endpoint->queryParameters))
<div class="sl-stack sl-stack--vertical sl-stack--6 sl-flex sl-flex-col sl-items-stretch">
<h3 class="sl-text-2xl sl-leading-snug sl-font-prose">Query Parameters</h3>
<h3 class="sl-text-2xl sl-leading-snug sl-font-prose">{{ __("scribe::endpoint.query_parameters") }}</h3>

<div class="sl-text-sm">
@foreach($endpoint->queryParameters as $attribute => $parameter)
Expand All @@ -115,7 +115,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }

@if(count($endpoint->nestedBodyParameters))
<div class="sl-stack sl-stack--vertical sl-stack--6 sl-flex sl-flex-col sl-items-stretch">
<h3 class="sl-text-2xl sl-leading-snug sl-font-prose">Body Parameters</h3>
<h3 class="sl-text-2xl sl-leading-snug sl-font-prose">{{ __("scribe::endpoint.body_parameters") }}</h3>

<div class="sl-text-sm">
@component('scribe::themes.elements.components.nested-fields', [
Expand All @@ -129,7 +129,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }

@if(count($endpoint->responseFields))
<div class="sl-stack sl-stack--vertical sl-stack--6 sl-flex sl-flex-col sl-items-stretch">
<h3 class="sl-text-2xl sl-leading-snug sl-font-prose">Response Fields</h3>
<h3 class="sl-text-2xl sl-leading-snug sl-font-prose">{{ __("scribe::endpoint.response_fields") }}</h3>

<div class="sl-text-sm">
@component('scribe::themes.elements.components.nested-fields', [
Expand Down Expand Up @@ -157,7 +157,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
<div class="sl-panel__titlebar sl-flex sl-items-center sl-relative focus:sl-z-10 sl-text-base sl-leading-none sl-pr-3 sl-pl-4 sl-bg-canvas-200 sl-text-body sl-border-input focus:sl-border-primary sl-select-none">
<div class="sl-flex sl-flex-1 sl-items-center sl-h-lg">
<div class="sl--ml-2">
Request sample:
{{ __("scribe::example_request") }}:
<select class="example-request-lang-toggle sl-text-base"
aria-label="Request Sample Language"
onchange="switchExampleLanguage(event.target.value);">
Expand Down Expand Up @@ -187,7 +187,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
<div class="sl-flex sl-flex-1 sl-items-center sl-py-2">
<div class="sl--ml-2">
<div class="sl-h-sm sl-text-base sl-font-medium sl-px-1.5 sl-text-muted sl-rounded sl-border-transparent sl-border">
<div class="sl-mb-2 sl-inline-block">Response sample:</div>
<div class="sl-mb-2 sl-inline-block">{{ __("scribe::example_response") }}:</div>
<div class="sl-mb-2 sl-inline-block">
<select
class="example-response-{{ $endpoint->endpointId() }}-toggle sl-text-base"
Expand Down Expand Up @@ -240,9 +240,9 @@ class="svg-inline--fa fa-chevron-right fa-fw sl-icon sl-text-muted"
</details>
@endif
@if(is_string($response->content) && Str::startsWith($response->content, "<<binary>>"))
<pre><code>[Binary data] - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}</code></pre>
<pre><code>[{{ __("scribe::example_response.binary") }}] - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}</code></pre>
@elseif($response->status == 204)
<pre><code>[Empty response]</code></pre>
<pre><code>[{{ __("scribe::example_response.empty") }}]</code></pre>
@else
@php($parsed = json_decode($response->content))
{{-- If response is a JSON string, prettify it. Otherwise, just print it --}}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/themes/elements/try_it_out.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class="sl-relative sl-w-full sl-h-md sl-text-base sl-pr-2.5 sl-pl-2.5 sl-rounded
<button type="button" data-endpoint="{{ $endpoint->endpointId() }}"
class="tryItOut-btn sl-button sl-h-sm sl-text-base sl-font-medium sl-px-1.5 sl-bg-primary hover:sl-bg-primary-dark active:sl-bg-primary-darker disabled:sl-bg-canvas-100 sl-text-on-primary disabled:sl-text-body sl-rounded sl-border-transparent sl-border disabled:sl-opacity-70"
>
Send API Request
{{ __("scribe::try_it_out.send") }}
</button>
</div>
</div>
Expand Down
Loading

0 comments on commit 4fd2a26

Please sign in to comment.