From 4fd2a2645ab26eb24f6dc0f8777fd05275e92fd4 Mon Sep 17 00:00:00 2001
From: shalvah
Date: Fri, 21 Apr 2023 14:51:56 +0200
Subject: [PATCH 1/2] Internationalization: Extract strings
---
lang/en.json | 32 +++++++++++++++++++
resources/js/tryitout.js | 5 ++-
resources/views/markdown/auth.blade.php | 4 +--
resources/views/markdown/intro.blade.php | 4 +--
.../views/themes/default/endpoint.blade.php | 32 +++++++++----------
.../views/themes/default/sidebar.blade.php | 6 ++--
.../views/themes/elements/endpoint.blade.php | 18 +++++------
.../themes/elements/try_it_out.blade.php | 2 +-
src/Extracting/ApiDetails.php | 30 +++++++----------
src/ScribeServiceProvider.php | 5 +++
src/Writing/HtmlWriter.php | 4 +--
.../Responses/UseApiResourceTagsTest.php | 7 +---
.../Responses/UseResponseAttributesTest.php | 4 +--
tests/Unit/HtmlWriterTest.php | 4 +--
14 files changed, 92 insertions(+), 65 deletions(-)
create mode 100644 lang/en.json
diff --git a/lang/en.json b/lang/en.json
new file mode 100644
index 00000000..2765e705
--- /dev/null
+++ b/lang/en.json
@@ -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"
+}
diff --git a/resources/js/tryitout.js b/resources/js/tryitout.js
index b618617d..21ee28e7 100644
--- a/resources/js/tryitout.js
+++ b/resources/js/tryitout.js
@@ -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}]`)
@@ -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;
@@ -266,6 +268,7 @@ async function executeTryOut(endpointId, form) {
handleError(endpointId, err);
})
.finally(() => {
+ executeBtn.disabled = false;
executeBtn.textContent = "Send Request 💥";
});
}
diff --git a/resources/views/markdown/auth.blade.php b/resources/views/markdown/auth.blade.php
index 3117dccd..3bc8d96e 100644
--- a/resources/views/markdown/auth.blade.php
+++ b/resources/views/markdown/auth.blade.php
@@ -1,7 +1,7 @@
-# Authenticating requests
+# {{ __("scribe::headers.auth") }}
@if(!$isAuthed)
-This API is not authenticated.
+{!! __("scribe::no_auth") !!}
@else
{!! $authDescription !!}
diff --git a/resources/views/markdown/intro.blade.php b/resources/views/markdown/intro.blade.php
index 9386e70c..febe2b99 100644
--- a/resources/views/markdown/intro.blade.php
+++ b/resources/views/markdown/intro.blade.php
@@ -1,9 +1,9 @@
-# Introduction
+# {{ __("scribe::headers.introduction") }}
{!! $description !!}
{!! $introText !!}
diff --git a/resources/views/themes/default/endpoint.blade.php b/resources/views/themes/default/endpoint.blade.php
index 1765d184..d6874602 100644
--- a/resources/views/themes/default/endpoint.blade.php
+++ b/resources/views/themes/default/endpoint.blade.php
@@ -12,7 +12,7 @@
{!! Parsedown::instance()->text($endpoint->metadata->description ?: '') !!}
-Example request:
+{{ __("scribe::example_request") }}:
@foreach($metadata['example_languages'] as $language)
@@ -27,7 +27,7 @@
@if($endpoint->isGet() || $endpoint->hasResponses())
@foreach($endpoint->responses as $response)
- Example response ({{ $response->fullDescription() }}):
+ {{ __("scribe::example_response") }} ({{ $response->fullDescription() }}):
@if(count($response->headers))
@@ -39,9 +39,9 @@
@endforeach @endif
@if(is_string($response->content) && Str::startsWith($response->content, "<>"))
-[Binary data] - {{ htmlentities(str_replace("<>", "", $response->content)) }}
+{!! __("scribe::example_response.binary") !!} - {{ htmlentities(str_replace("<>", "", $response->content)) }}
@elseif($response->status == 204)
-[Empty response]
+{!! __("scribe::example_response.empty") !!}
@else
@php($parsed = json_decode($response->content))
{{-- If response is a JSON string, prettify it. Otherwise, just print it --}}
@@ -51,13 +51,13 @@
@endif
- Received response{{ __("scribe::try_it_out.received_response") }}:
- Request failed with error:
+ {{ __("scribe::try_it_out.request_failed") }}:
@endforeach
@if(count($endpoint->headers))
- Headers
+ {{ __("scribe::endpoint.headers") }}
@foreach($endpoint->headers as $name => $example)
urlParameters))
- URL Parameters
+ {{ __("scribe::endpoint.url_parameters") }}
@foreach($endpoint->urlParameters as $attribute => $parameter)
@component('scribe::components.field-details', [
@@ -136,7 +136,7 @@
@endforeach
@endif
@if(count($endpoint->queryParameters))
-
Query Parameters
+ {{ __("scribe::endpoint.query_parameters") }}
@foreach($endpoint->queryParameters as $attribute => $parameter)
nestedBodyParameters))
- Body Parameters
+ {{ __("scribe::endpoint.body_parameters") }}
@@ -169,8 +169,8 @@
@if(count($endpoint->responseFields))
- Response
- Response Fields
+ {{ __("scribe::endpoint.response") }}
+ {{ __("scribe::endpoint.response_fields") }}
-
+
@@ -52,10 +52,10 @@
diff --git a/resources/views/themes/elements/endpoint.blade.php b/resources/views/themes/elements/endpoint.blade.php
index 1e3502b4..d3757cbd 100644
--- a/resources/views/themes/elements/endpoint.blade.php
+++ b/resources/views/themes/elements/endpoint.blade.php
@@ -48,7 +48,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
@if(count($endpoint->headers))
- Headers
+ {{ __("scribe::endpoint.headers") }}
@foreach($endpoint->headers as $header => $value)
@@ -70,7 +70,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
@if(count($endpoint->urlParameters))
-
URL Parameters
+
{{ __("scribe::endpoint.url_parameters") }}
@foreach($endpoint->urlParameters as $attribute => $parameter)
@@ -93,7 +93,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
@if(count($endpoint->queryParameters))
-
Query Parameters
+
{{ __("scribe::endpoint.query_parameters") }}
@foreach($endpoint->queryParameters as $attribute => $parameter)
@@ -115,7 +115,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
@if(count($endpoint->nestedBodyParameters))
-
Body Parameters
+
{{ __("scribe::endpoint.body_parameters") }}
@component('scribe::themes.elements.components.nested-fields', [
@@ -129,7 +129,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
@if(count($endpoint->responseFields))
-
Response Fields
+
{{ __("scribe::endpoint.response_fields") }}
@component('scribe::themes.elements.components.nested-fields', [
@@ -157,7 +157,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
- Request sample:
+ {{ __("scribe::example_request") }}:
-
-
1. Double check that your computer is connected to
- the internet.
-
2. Make sure the API is actually running and
- available under the specified URL.
-
3. If you've checked all of the above and still experiencing issues,
- check if the API supports CORS.
-
+
+
{{ __("scribe::try_it_out.error_help") }}
@@ -314,13 +304,15 @@ class="svg-inline--fa fa-caret-down fa-fw sl-icon" role="img"
d="M310.6 246.6l-127.1 128C176.4 380.9 168.2 384 160 384s-16.38-3.125-22.63-9.375l-127.1-128C.2244 237.5-2.516 223.7 2.438 211.8S19.07 192 32 192h255.1c12.94 0 24.62 7.781 29.58 19.75S319.8 237.5 310.6 246.6z">
- Response
+ {{ __("scribe::try_it_out.received_response") }}
-
+
"
+ style="max-height: 300px;">