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

Possibility to change lang folder path #13

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "jobilla/laravel-loco-tms",
"name": "slgo99/laravel-loco-tms",
"description": "A Laravel convenience integration for the Loco translation management system",
"type": "library",
"require": {
"ext-json": "*",
"illuminate/console": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/filesystem": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/translation": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/console": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/filesystem": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/translation": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
"loco/loco": "^1.0|^2.0|2.0.x-dev"
},
"require-dev": {
Expand Down
1 change: 1 addition & 0 deletions config/loco.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

return [
'api_key' => env('LOCO_API_KEY'),
'lang_path' => lang_path(),
];
38 changes: 35 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,48 @@ This is an integration with the [Loco Translation Management System](https://loc
## Installation

```sh
composer require jobilla/laravel-loco-tms
composer require slgo99/laravel-loco-tms
```

## Configuration

To use the library, you'll need to set your Loco API Key for your translation project.
Either set the environment variable `LOCO_API_KEY`, or publish the configuration file
and update it with another value.
Set the environment variable `LOCO_API_KEY`.

Then you'll need to publish the configuration file.

To publish the configuration file, run:
```sh
php artisan vendor:publish --provider="Jobilla\Loco\LocoServiceProvider"
```
This will create a `loco.php` file in your `config` directory.

The configuration file should look like this:
```php
return [
'api_key' => env('LOCO_API_KEY'),
'lang_path' => resource_path('lang'),
];
```
The `lang_path` is the path where the translations will be stored.
In Laravel 9+ projects, you might need to set the `lang_path` to `base_path('lang')`.

## Usage

### Importing translations

To download translations from Loco, run the following command:

```sh
php artisan loco:download
```
This will download all translations from Loco and store them in the `lang_path` directory.

### Exporting translations

To upload translations to Loco, run the following command:

```sh
php artisan loco:upload
```
This will upload all translations from the `lang_path` directory to Loco.
2 changes: 1 addition & 1 deletion src/Commands/DownloadTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function handle(ApiClient $client, Translator $translator, FilesystemMana
]);

$translations = $this->dropEmptyString(json_decode((string)$res, JSON_OBJECT_AS_ARRAY));
$fs = $storage->createLocalDriver(['root' => resource_path('lang')]);
$fs = $storage->createLocalDriver(['root' => config('loco.lang_path')]);

foreach ($translations as $lang => $groups) {
$this->info("Writing translation files for $lang...");
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/UploadTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class UploadTranslations extends Command
*/
public function handle(ApiClient $client, Translator $translator, FilesystemManager $storage)
{
$fs = $storage->createLocalDriver(['root' => resource_path('lang')]);
$fs = $storage->createLocalDriver(['root' => config('loco.lang_path')]);
$locales = count($this->option('locale')) ? $this->option('locale') : $fs->directories();
foreach ($locales as $locale) {
$translations = [];
Expand Down
2 changes: 2 additions & 0 deletions src/LocoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class LocoServiceProvider extends AggregateServiceProvider
{
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/loco.php', 'loco');

$this->app->bind(ApiClient::class, function ($app) {
return ApiClient::factory([
'version' => '1.0',
Expand Down