Skip to content

Commit

Permalink
Merge pull request #31 from masterix21/feature-json-translations
Browse files Browse the repository at this point in the history
Add json translations support
  • Loading branch information
freekmurze authored May 22, 2021
2 parents a28108b + dcd656d commit 2bd4d3d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ trans('your-package-name::translations.translatable'); // returns 'translation'

If your package name starts with `laravel-` then you should leave that off in the example above.

Coding with translation strings as keys, you should create JSON files in `<package root>/resources/lang/<language-code>.json`.

For example, creating `<package root>/resources/lang/it.json` file like so:

```json
{
"Hello!": "Ciao!"
}
```

...the output of...

```php
trans('Hello!');
```

...will be `Ciao!` if the application uses the Italian language.

Calling `hasTranslations` will also make translations publishable. Users of your package will be able to publish the translations with this command:

Expand Down
3 changes: 3 additions & 0 deletions src/PackageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public function boot()
$this->package->basePath('/../resources/lang/'),
$this->package->shortName()
);

$this->loadJsonTranslationsFrom($this->package->basePath('/../resources/lang/'));
$this->loadJsonTranslationsFrom(resource_path('lang/vendor/'. $this->package->shortName()));
}

if ($this->package->hasViews) {
Expand Down

0 comments on commit 2bd4d3d

Please sign in to comment.