@component('scribe::themes.elements.components.nested-fields', [
@@ -129,7 +130,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
@if(count($endpoint->responseFields))
-
{{ __("scribe::endpoint.response_fields") }}
+
{{ u::trans("scribe::endpoint.response_fields") }}
@component('scribe::themes.elements.components.nested-fields', [
@@ -157,7 +158,7 @@ class="sl-overflow-x-hidden sl-truncate sl-text-muted">{{ rtrim($baseUrl, '/') }
- {{ __("scribe::example_request") }}:
+ {{ u::trans("scribe::example_request") }}:
@@ -304,14 +305,14 @@ 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">
- {{ __("scribe::try_it_out.received_response") }}
+ {{ u::trans("scribe::try_it_out.received_response") }}
"
+ data-empty-response-text="<{{ u::trans("scribe::example_response.empty") }}>"
style="max-height: 300px;">
diff --git a/src/Extracting/ApiDetails.php b/src/Extracting/ApiDetails.php
index 9c2995f3..febe4b9c 100644
--- a/src/Extracting/ApiDetails.php
+++ b/src/Extracting/ApiDetails.php
@@ -3,6 +3,7 @@
namespace Knuckles\Scribe\Extracting;
use Knuckles\Scribe\Tools\ConsoleOutputUtils as c;
+use Knuckles\Scribe\Tools\Utils as u;
use Knuckles\Scribe\Tools\DocumentationConfig;
/**
@@ -90,11 +91,11 @@ public function writeAuthMarkdownFile(): void
if ($isAuthed) {
$strategy = $this->config->get('auth.in');
$parameterName = $this->config->get('auth.name');
- $authDescription = __("scribe::auth.instruction.$strategy", [
+ $authDescription = u::trans("scribe::auth.instruction.$strategy", [
'parameterName' => $parameterName,
'placeholder' => $this->config->get('auth.placeholder') ?: 'your-token']
);
- $authDescription .= "\n\n".__("scribe::auth.details");
+ $authDescription .= "\n\n".u::trans("scribe::auth.details");
$extraInfo = $this->config->get('auth.extra_info', '');
}
diff --git a/src/Tools/Utils.php b/src/Tools/Utils.php
index 294ac9e7..5d183718 100644
--- a/src/Tools/Utils.php
+++ b/src/Tools/Utils.php
@@ -353,6 +353,26 @@ public static function filterDocBlockTags(array $tags, string ...$names): array
);
}
+ /**
+ * Like Laravel's trans/__ function, but will fallback to using the default translation if translation fails.
+ * For instance, if the user's locale is DE, but they have no DE strings defined,
+ * Laravel simply renders the translation key.
+ * Instead, we render the EN version.
+ */
+ public static function trans(string $key, array $replace = [])
+ {
+ $translation = trans($key, $replace);
+
+ if ($translation === $key) {
+ $translation = trans($key, $replace, config('app.fallback_locale'));
+ }
+
+ if ($translation === $key) {
+ return trans($key, $replace, 'en');
+ }
+
+ return $translation;
+ }
}
function getTopLevelItemsFromMixedOrderList(array $mixedList): array
diff --git a/src/Writing/HtmlWriter.php b/src/Writing/HtmlWriter.php
index d1f52160..b40b8522 100644
--- a/src/Writing/HtmlWriter.php
+++ b/src/Writing/HtmlWriter.php
@@ -9,6 +9,7 @@
use Knuckles\Scribe\Tools\DocumentationConfig;
use Knuckles\Scribe\Tools\MarkdownParser;
use Knuckles\Scribe\Tools\Utils;
+use Knuckles\Scribe\Tools\Utils as u;
use Knuckles\Scribe\Tools\WritingUtils;
/**
@@ -112,11 +113,11 @@ public function getMetadata(): array
// NB:These paths are wrong for laravel type but will be set correctly by the Writer class
if ($this->config->get('postman.enabled', true)) {
- $links[] = "
assetPathPrefix}collection.json\">".__("scribe::links.postman")."";
+ $links[] = "
assetPathPrefix}collection.json\">".u::trans("scribe::links.postman")."";
$postmanCollectionUrl = "{$this->assetPathPrefix}collection.json";
}
if ($this->config->get('openapi.enabled', false)) {
- $links[] = "
assetPathPrefix}openapi.yaml\">".__("scribe::links.openapi")."";
+ $links[] = "
assetPathPrefix}openapi.yaml\">".u::trans("scribe::links.openapi")."";
$openApiSpecUrl = "{$this->assetPathPrefix}openapi.yaml";
}