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

feat: add localization #27

Merged
merged 1 commit into from
Feb 8, 2021
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
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```
10 changes: 6 additions & 4 deletions resources/js/components/CreateToken.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
>
<div>
<h2 class="border-b border-40 py-8 px-8 text-90 font-normal text-xl">
Create Personal Access Token
{{ __("Create Personal Access Token") }}
</h2>
<div>
<div class="action">
Expand All @@ -18,7 +18,7 @@
<label
for="name"
class="inline-block text-80 pt-2 leading-tight"
>Name</label
>{{ __("Name") }}</label
>
</div>
<div class="py-6 px-8 w-1/2">
Expand All @@ -32,14 +32,16 @@
<label
for="scopes"
class="inline-block text-80 pt-2 leading-tight"
>Abilities</label
>{{ __("Abilities") }}</label
>
</div>
<div class="py-6 px-8 w-1/2">
<slot name="abilities"></slot>

<div class="help-text help-text mt-2">
Comma separated list of abilities to apply to token.
{{
__("Comma separated list of abilities to apply to token.")
}}
</div>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion resources/js/components/DeleteToken.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
{{ __("Delete Token") }}
</heading>
<p class="text-80 leading-normal">
Are you sure you want to delete the {{ token.name }} token?
{{
__("Are you sure you want to delete the :token token?", {
token: token.name,
})
}}
</p>
</div>

Expand Down
11 changes: 7 additions & 4 deletions resources/js/components/ShowToken.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
>
<div>
<h2 class="border-b border-40 py-8 px-8 text-90 font-normal text-xl">
Personal Access Token
{{ __("Personal Access Token") }}
</h2>
<div>
<div class="action">
Expand Down Expand Up @@ -35,8 +35,11 @@
</div>
<div class="flex items-center ml-3">
<p class="text-sm leading-5 text-yellow-700">
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!"
)
}}
</p>
</div>
</div>
Expand All @@ -53,7 +56,7 @@
type="submit"
class="btn btn-default btn-primary"
>
Got it!
{{ __(`Confirm`) }}
</button>
</div>
</div>
Expand Down
18 changes: 10 additions & 8 deletions resources/js/components/Tool.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<template>
<div class="relative" dusk="profiles-index-component">
<h1 class="mb-3 text-90 font-normal text-2xl">Personal Access Tokens</h1>
<h1 class="mb-3 text-90 font-normal text-2xl">
{{ __("Personal Access Tokens") }}
</h1>
<div class="flex" style>
<div class="w-full flex items-center">
<div class="flex-no-shrink ml-auto mb-6">
<button
@click="showAddModal = true"
class="btn btn-default btn-primary"
>
Create Token
{{ __("Create Token") }}
</button>
</div>
</div>
Expand All @@ -22,13 +24,13 @@
<thead>
<tr>
<th class="text-left">
<span>Name</span>
<span>{{ __("Name") }}</span>
</th>
<th class="text-left" v-if="panel.options.showAbilities">
<span>Abilities</span>
<span>{{ __("Abilities") }}</span>
</th>
<th class="text-left">
<span>Last Used At</span>
<span>{{ __("Last Used At") }}</span>
</th>
<th>&nbsp;</th>
</tr>
Expand Down Expand Up @@ -60,14 +62,14 @@
/>
</svg>
<h3 class="text-base text-80 font-normal mb-6">
No Tokens For User.
{{ __("No Tokens For User.") }}
</h3>
<div>
<button
@click="showAddModal = true"
class="btn btn-sm btn-outline inline-flex items-center focus:outline-none focus:shadow-outline active:outline-none active:shadow-outline"
>
Create Token
{{ __("Create Token") }}
</button>
</div>
</div>
Expand Down Expand Up @@ -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"
/>
</svg>
Copy
{{ __("Copy") }}
</button>
</show-token>
</portal>
Expand Down
17 changes: 17 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
@@ -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"
}
39 changes: 38 additions & 1 deletion src/ToolServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

class ToolServiceProvider extends ServiceProvider
{
/**
* Component identifier name.
*
* @var string
*/
public static $name = "sanctum-tokens";

/**
* Bootstrap any application services.
*
Expand All @@ -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.
*
Expand All @@ -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");
}

Expand Down