diff --git a/readme.md b/readme.md
index 828fb3a..3bfd8e9 100644
--- a/readme.md
+++ b/readme.md
@@ -93,3 +93,11 @@ public function fields(Request $request)
}
```
+
+### Localization
+
+Publish the package language files to your application's `resources/lang/vendor` directory:
+
+```
+php artisan vendor:publish --provider="Jeffbeltran\SanctumTokens\ToolServiceProvider"
+```
diff --git a/resources/js/components/CreateToken.vue b/resources/js/components/CreateToken.vue
index afd0307..f4f63cf 100644
--- a/resources/js/components/CreateToken.vue
+++ b/resources/js/components/CreateToken.vue
@@ -8,7 +8,7 @@
>
- Create Personal Access Token
+ {{ __("Create Personal Access Token") }}
@@ -18,7 +18,7 @@
Name {{ __("Name") }}
@@ -32,14 +32,16 @@
Abilities {{ __("Abilities") }}
- Comma separated list of abilities to apply to token.
+ {{
+ __("Comma separated list of abilities to apply to token.")
+ }}
diff --git a/resources/js/components/DeleteToken.vue b/resources/js/components/DeleteToken.vue
index e15e768..4e8184f 100644
--- a/resources/js/components/DeleteToken.vue
+++ b/resources/js/components/DeleteToken.vue
@@ -10,7 +10,11 @@
{{ __("Delete Token") }}
- Are you sure you want to delete the {{ token.name }} token?
+ {{
+ __("Are you sure you want to delete the :token token?", {
+ token: token.name,
+ })
+ }}
diff --git a/resources/js/components/ShowToken.vue b/resources/js/components/ShowToken.vue
index ff4bb83..f075e45 100644
--- a/resources/js/components/ShowToken.vue
+++ b/resources/js/components/ShowToken.vue
@@ -7,7 +7,7 @@
>
- Personal Access Token
+ {{ __("Personal Access Token") }}
@@ -35,8 +35,11 @@
- Make sure to copy your new personal access token now.
- You won't be able to see it again!
+ {{
+ __(
+ "Make sure to copy your new personal access token now. You won't be able to see it again!"
+ )
+ }}
@@ -53,7 +56,7 @@
type="submit"
class="btn btn-default btn-primary"
>
- Got it!
+ {{ __(`Confirm`) }}
diff --git a/resources/js/components/Tool.vue b/resources/js/components/Tool.vue
index 3d55f56..66230e6 100644
--- a/resources/js/components/Tool.vue
+++ b/resources/js/components/Tool.vue
@@ -1,6 +1,8 @@
-
Personal Access Tokens
+
+ {{ __("Personal Access Tokens") }}
+
@@ -8,7 +10,7 @@
@click="showAddModal = true"
class="btn btn-default btn-primary"
>
- Create Token
+ {{ __("Create Token") }}
@@ -22,13 +24,13 @@
- Name
+ {{ __("Name") }}
- Abilities
+ {{ __("Abilities") }}
- Last Used At
+ {{ __("Last Used At") }}
@@ -60,14 +62,14 @@
/>
- No Tokens For User.
+ {{ __("No Tokens For User.") }}
- Create Token
+ {{ __("Create Token") }}
@@ -131,7 +133,7 @@
d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"
/>
- Copy
+ {{ __("Copy") }}
diff --git a/resources/lang/en.json b/resources/lang/en.json
new file mode 100644
index 0000000..1ef3a77
--- /dev/null
+++ b/resources/lang/en.json
@@ -0,0 +1,17 @@
+{
+ "Abilities": "Abilities",
+ "Are you sure you want to delete the :token token?": "Are you sure you want to delete the :token token?",
+ "Cancel": "Cancel",
+ "Comma separated list of abilities to apply to token.": "Comma separated list of abilities to apply to token.",
+ "Confirm": "Confirm",
+ "Copy": "Copy",
+ "Create Personal Access Token": "Create Personal Access Token",
+ "Create Token": "Create Token",
+ "Delete Token": "Delete Token",
+ "Last Used At": "Last Used At",
+ "Make sure to copy your new personal access token now. You won't be able to see it again!": "Make sure to copy your new personal access token now. You won't be able to see it again!",
+ "Name": "Name",
+ "No Tokens For User.": "No Tokens For User.",
+ "Personal Access Token": "Personal Access Token",
+ "Personal Access Tokens": "Personal Access Tokens"
+}
diff --git a/src/ToolServiceProvider.php b/src/ToolServiceProvider.php
index de00601..8edc724 100644
--- a/src/ToolServiceProvider.php
+++ b/src/ToolServiceProvider.php
@@ -9,6 +9,13 @@
class ToolServiceProvider extends ServiceProvider
{
+ /**
+ * Component identifier name.
+ *
+ * @var string
+ */
+ public static $name = "sanctum-tokens";
+
/**
* Bootstrap any application services.
*
@@ -20,12 +27,42 @@ public function boot()
$this->routes();
});
+ $this->publishes([
+ __DIR__ . "/../resources/lang" => resource_path(
+ "lang/vendor/" . static::$name
+ ),
+ ]);
+
Nova::serving(function (ServingNova $event) {
Nova::script("sanctum-tokens", __DIR__ . "/../dist/js/tool.js");
Nova::style("sanctum-tokens", __DIR__ . "/../dist/css/tool.css");
+ Nova::translations(static::getTranslations());
});
}
+ /**
+ * Get the translation keys from file.
+ *
+ * @return array
+ */
+ private static function getTranslations(): array
+ {
+ $translationFile = resource_path(
+ "lang/vendor/" . static::$name . "/" . app()->getLocale() . ".json"
+ );
+
+ if (!is_readable($translationFile)) {
+ $translationFile =
+ __DIR__ . "/../resources/lang/" . app()->getLocale() . ".json";
+
+ if (!is_readable($translationFile)) {
+ return [];
+ }
+ }
+
+ return json_decode(file_get_contents($translationFile), true);
+ }
+
/**
* Register the tool's routes.
*
@@ -38,7 +75,7 @@ protected function routes()
}
Route::middleware(["nova"])
- ->prefix("nova-vendor/sanctum-tokens")
+ ->prefix("nova-vendor/" . static::$name)
->group(__DIR__ . "/../routes/api.php");
}