joedixon / laravel-translation Goto Github PK
View Code? Open in Web Editor NEWTranslation management for your Laravel application.
License: MIT License
Translation management for your Laravel application.
License: MIT License
The command that properly creates the file when you publish the configuration is:
php artisan vendor:publish --provider="JoeDixon\Translation\TranslationServiceProvider"
and not php artisan vendor:publish --provider=JoeDixon\\Translation\\TranslationServiceProvider
as defined in the documentation.
Regards
Describe the bug
A clear and concise description of what the bug is.
php artisan translation: sync-missing-translation keys returns an error.
To Reproduce
Steps to reproduce the behavior:
Try the command.
Expected behavior
To work properly
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Fix:
Fix the typo in Src/Console/Commands/Synchronise<issingTranslationKeys.php, line 12
I've installed the package as per git readme file and i moved the dev version of my project to LIVE
So i need to change my dev public index.php and .htaccess to root directory
now if i change in local machine with php artisan serve it works fine but when i try in my live project it doesnt work and say
POST http://mysite.com/lang/en 404 (Not Found)
All i changed is copied those two files to root directory
Laravel verison is 6.6.0
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Allow developer to totally disables the frontend ui, especially if they already use your nova packages.
Describe the solution you'd like
A clear and concise description of what you want to happen.
we can put a new config called disable_ui and then wrap the config value at web.php file
if (config('translation.disable_ui', false) {
return;
}
Route........
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Describe the bug
Single translations not working with Database driver.
To Reproduce
Lang::getFromJson('Reset Password Notification')
Expected behavior
The value of Lang::getFromJson('Reset Password Notification')
should be "Test" but we have "Reset Password Notification".
Additional context
getSingleTranslationsFor()
function return a collection with single
key and vendor:single
keys.
But getFromJson
Laravel method expects a single level (https://github.com/laravel/framework/blob/5.8/src/Illuminate/Translation/Translator.php#L154).
Potential solution : add ->collapse()
to getSingleTranslationsFor
result (working for me)
Problem
After add/update translation, there should be return file path or alternative method where we can get the updated file path.
Solution can be !!
namespace JoeDixon\Translation\Drivers;
private function saveGroupTranslations($language, $group, $translations)
{
....
$this->file_path = "{$this->languageFilesPath}".DIRECTORY_SEPARATOR."{$language}".DIRECTORY_SEPARATOR."{$group}.php";
if($this->disk->put($$this->file_path, "<?php\n\nreturn ".var_export($translations, true).';'.\PHP_EOL))
{
return array('updated_file',$this->file_path, 'success'=>true);
}
return false;
}
public function addSingleTranslation($language, $vendor, $key, $value = '')
{
return $this->saveSingleTranslations($language, $translations);
}
-------------
OR
-----------
public function recentUpdatedFIle()
{
return $this->file_path;
}
Hello,
I receive an error when call in my code:
Artisan::call("translation:sync-missing-translation-keys");
Error
The command "translation:sync-missing-translation-keys" does not exist.
I use model within my laravel app and each module has it's own resource folder that contains the lang file so I wonder is there any way to change the path that the package get and write the translation to
regards ..
Describe the bug
The command signature also has the same typo as the readme that got fixed previously.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The typo in command signature should also be fixed, so we can properly use the command.
Screenshots
protected $signature = 'translation:sync-missing-tranlsation-keys {language?}';
Desktop (please complete the following information):
I use validation files that have nested arrays. In short, nested arrays aren't visible or editable in translation manager list. I also tried to replace arrays with "." string but then it's only visible, not editable...
It would be nice if someone could modify package to support nested arrays or there is alternative?
Is your feature request related to a problem? Please describe.
No, this relates more to the tutorial I found on laravelnews.com
Describe the solution you'd like
It woud be helpful to be able to easily navigation between the various parts of the tutorial. After Part 2, there is no link to the next part.
Describe alternatives you've considered
Starting from the latest part that was published, I had to work backwards using the link at the beginning of each part.
Describe the bug
The key
index is duplicated in the translation files
To Reproduce
Steps to reproduce the behavior:
de
, ru
etcExpected behavior
We expect a single key => value
pair
Desktop (please complete the following information):
Hey @joedixon, good job on the project. I like it very much.
Do you have any plan to integrate into Laravel Nova?
*I can't find languages route
My App has middleware that redirect the url into : http://webapp.test/{locale}
if I need this route : http://webapp.test/languges it will redirect to : http://webapp.test/{locale}/languges and it return page not found
Describe the bug
The /languages/{lang}/translations
page doesn't work.
To Reproduce
Steps to reproduce the behavior:
composer require joedixon/laravel-translation
php artisan vendor:publish --provider="JoeDixon\Translation\TranslationServiceProvider"
Expected behavior
It should work.
Desktop (please complete the following information):
https://mysite.com/en/languages
gives a 404
It doesn't publish all the file with this method
php artisan vendor:publish --provider=JoeDixon\Translation\TranslationServiceProvider
When adding to translate it doesn't save showing
URL: http://localisation.test/languages/te/translations
it takes the file path instead of urla and giving a 404 error
The requested URL /languages/D:\file_path\localisation\resources\lang\bn/translations was not found on this server.
and got a woops warning of
ErrorException (E_WARNING)
mkdir(): File exists
I'm using this package to access phrases from Vue components:
https://www.npmjs.com/package/@kirschbaum-development/laravel-translations-loader
In short is allows you to use phrases via $t()
function within vue templates and this.$t()
within Vue component's logic.
Is it possible to sync missing keys from Vue files too, when I run php artisan translation:sync-missing-tranlsation-keys
?
Describe the bug
when i try to install it i get this.
Laravel 6:
Additional context
Illuminate\Foundation\ComposerScripts::postAutoloadDump
@php artisan package:discover --ansi
Symfony\Component\Debug\Exception\FatalThrowableError : Unsupported operand types
at C:\wamp64\www\laravel\myproject\vendor\joedixon\laravel-translation\routes\web.php:3
1| <?php
2|
3| Route::group(config('translation.route_group_config') + ['namespace' => 'JoeDixon\Translation\Http\Controllers'], function ($router) {
4| $router->get(config('translation.ui_url'), 'LanguageController@index')
5| ->name('languages.index');
6|
7| $router->get(config('translation.ui_url').'/create', 'LanguageController@create')
8| ->name('languages.create');
9|
Exception trace:
1 require()
C:\wamp64\www\laravel\myproject\vendor\laravel\framework\src\Illuminate\Support\ServiceProvider.php:77
2 Illuminate\Support\ServiceProvider::loadRoutesFrom("C:\wamp64\www\laravel\myproject\vendor\joedixon\laravel-translation\src/../routes/web.php")
C:\wamp64\www\laravel\myproject\vendor\joedixon\laravel-translation\src\TranslationServiceProvider.php:77
Please use the argument -v to see more details.
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Not working on 5.4 do you have any idea about it not publishing any configuration ?
sorry for this request.
I just wish this package provide 'app.js' source code as before webpacked.
translation:sync-missing-tranlsation-keys
Description
We're using the library on a rebuild project with thousands of translation lines, about half of the keys have a full-stop either in the middle of the key name or at the end.
When running the database -> file sync command, any characters after the first full-stop (inclusive) in the key name are dumped in the generated files, so for example:
group = "newsletter"
key = "Welcome. Your name."
value = "Welcome. Please enter your name."
would be represented in the lang file as follows:
return [ "Welcome" => "Welcome. Please enter your name." ]
Instead of:
return [ "Welcome. Your name" => "Welcome. Please enter your name." ]
To Reproduce
Ensuring you have a key containing a full-stop (period), simply run the sync command from database to file:
php artisan translation:sync-translations
Expected behavior
I expect that the key should be copied in full to the generated file, full-stops and all.
Desktop (please complete the following information):
Describe the bug
Laravel 6.0: All str_ and array_ helpers have been moved to the new laravel/helpers Composer package and removed from the framework.
Call to undefined function JoeDixon\Translation\Drivers\str_contains()
happens.
composer require laravel/helpers
will fix this issue. But I think codebase should move to Illuminate\Support\Str
too. So we can remove the legacy package again ^^
To Reproduce
Steps to reproduce the behavior:
/nova-vendor/nova-translation/languages/de/translations
http call.Expected behavior
no 500
Additional context
Add any other context about the problem here.
@debjit reported the following:
When adding to translate it doesn't save showing
URL: http://localisation.test/languages/te/translations
it takes the file path instead of urla and giving a 404 error
The requested URL /languages/D:\file_path\localisation\resources\lang\bn/translations was not found on this server.
and got a woops warning of
ErrorException (E_WARNING)
mkdir(): File exists
Is your feature request related to a problem? Please describe.
It looks like if the translation are stored in DB, every time a translation is needed the database is searched for it. This can slow down the site significantly. I can not see any caching for the queries.
Describe the solution you'd like
Add caching.
Hi,
first thanks for this awesome package.
When i edit a translation for the file, let's say, homepage/faq.php it will be displayed as "faq" in the first column.
Changes are saved in the root directory of the language files for the locale and not in the en/homepage/faq.php file but in the en/faq.php which didn't exist before.
I am using Laravel 6 with Apache 2.4 and Ubuntu 18.04
I have installed package with
composer require joedixon/laravel-translation
And then
php artisan vendor:publish --provider="JoeDixon\Translation\TranslationServiceProvider"
The route https://myproject.com/languages works fine
For translations I am using https://myproject.com/languages/en/translations and it gives following error:
Symfony \ Component \ Finder \ Exception \ DirectoryNotFoundException
The "/var/www/myproject.com/my-project/resources/lang/en_US:" directory does not exist.
You can find error log in attached error-log.txt.
If I check the "Translations" link in https://myproject.com/languages (please see attached "languages.png") then link seems like https://myproject.com/languages/en_US:/translations
However, I don't have any directory link "en_US:" neither I set "en_US:" anywhere in my project as well as I am using config/app.php
'locale'='en'
and 'fallback_locale' => 'en'
P.S. Everything works fine on my local windows 8 machine with WAMP. I am facing this error on ubuntu server.
Can you please let me know how to fix it?
After installing the newest 1.1.0 version, when trying to open the web interface I'm getting this error:
Illuminate\Contracts\Container\BindingResolutionException Target [JoeDixon\Translation\Drivers\Translation] is not instantiable while building [JoeDixon\Translation\Http\Controllers\LanguageTranslationController]
I'm guessing it has something to do with the commit from @joedixon from 6 days ago "Add multiple service providers"?
Tried php artisan config:clear
and php artisan clear-compiled
Using Laravel 6.13
Hey @joedixon thanks for the awesome work, love this package and the nova ui for it!
Not a real problem here, just an idea and question: Would you be interested in a PR that adds firing events when a translation is updated or created?
We use your package to add changed lang files to git via a Command and it would be awesome to run this command on an event and not every five minutes :D
Do you see any problems here? (besides feature creep, which would be a totally valid reason to say "no" to this idea too)
all the best!
Simon vom Eyser
After a fresh install, after loading all translations, when visiting
http://localhost:8000/languages/DE/translations
I get the error
Undefined index: EN
The error seems to be located here:
@if(!is_array($value[config('app.locale')]))
my app locale is
'locale' => 'en'
@debjit reported the following
It doesn't publish all the file with this method
php artisan vendor:publish --provider=JoeDixon\Translation\TranslationServiceProvider
Describe the bug
Database storage not working
To Reproduce
Initially I saved new language to file. Then I've followed all the instructions to save new languages to database in stead of a file. But a new added language is still being added as a file.
Desktop (please complete the following information):
Describe the bug
Sometimes, to organize the translation resources, is necesary to group them into a subfolder like this:
These files are detected ok, but when saving, doesn't save in the same place, instead, it is saved one level up and duplicates the original one.
Also, i think, would be util improve the interface adding the path like this:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The changes should be saved in the same file
Describe the bug
php artisan vendor:publish --provider=JoeDixon\\Translation\\TranslationServiceProvider
This command doesn't publish configuration and assets files. How can we debug this?
Laravel v5.7 latest
Is your feature request related to a problem? Please describe.
The problem is that we have more than 500 databases and I am not sure how to implement this so we can translate all the keys we have.
Describe the solution you'd like
I don't actually know. My question is actually: Can this package be used for a multi tenant platform or it's working only with a single database?
I would be happy if we could discuss this in 5 min so I could understand if this is something for us or not?
I have a lot of nested keys in my translation file e.g.
'content' => [
'text' => 'text',
'headline' => 'headline'
]
to get to a specific key it is possible to do __('content.text')
.
But if I am outside of the Laravel Blade context (e.g. in a Vue component)
I would like to give this component all relevant translations __('content')
This does not work with the Database Driver.
The database itself looks like this:
key | translation |
---|---|
content.text | text |
content.headline | headline |
If a non-leaf translation is requested all sub translations should be returned as an array.
__('content')
=> ['text' => 'text, 'headline' => 'headline']
The solutions to this problem are either to explicitly request every single translation or to overwrite the ServiceProvider and DatabaseLoader.
The changed Logic in the DatabaseLoader currently looks like this:
public function load($locale, $group, $namespace = null)
{
[...]
return $this->translation->getGroupTranslationsFor($locale)->filter(function ($value, $key) use ($group) {
return $key === $group;
})->first();
[...]
}
I propose changing it to:
public function load($locale, $group, $namespace = null)
{
[...]
$dotted = [];
$this->translation->getGroupTranslationsFor($locale)->filter(function ($value, $key) use ($group) {
return $key === $group;
})->first()->each(function ($key, $translation) use (&$dotted) {
Arr::set($dotted, $translation, $key);
});
return collect($dotted);
[...]
}
in Dirvers/file.php
It will be better use as following:
$vendor = str_before(str_after($file->getPathname(), 'vendor'.DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR);
User DIRECTORY_SEPARATOR not "/" or "" since it is different between in linux and in windows.
in Drivers/Translations.php
return $allTranslations->map(function ($groups, $type) use ($language, $filter) {
return $groups->map(function ($keys, $group) use ($language, $filter, $type) {
return collect($keys)->filter(function ($translations, $key) use ($group, $language, $filter, $type) {
return strs_contain([$group, $key, $translations[$language], $translations[$this->sourceLanguage]], $filter);
});
})->filter(function ($keys) {
return $keys->isNotEmpty();
});
});
this could make group name searchable, especially very useful in single type translation.
Dear Joe,
The problem is when I change locale (localization) of my app to other than defined in config/app.php file (which id 'en' by default), the translation pages (other than actual locale value page) stop working.
So, basically:
Please see the below video for more details:
https://streamable.com/b9qrb3
After a quick debug I found out that the problem seems to be that '$translations' array does not include the necessary index for the selected locale:
Best regards,
Radoslaw
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Describe the bug
The default translate.php
file has the key ui_url
used to customize which url should you navigate in order to produce navigate the UI. Customizing this works actually but noticed it doesn't save languages not does any ajax/vue callbacks successfully since it doesn't seem to see the url.
To Reproduce
Steps to reproduce the behavior:
config/translation.php
and change ui_url
to say something /administrative/languages
Expected behavior
Language suppose to save and show the green tick.
Desktop (please complete the following information):
Additional context
I think it could be a route problem cause the route/administrative/languages/en
doesn't exist and it is trying to to perform a request to the server code.
Is your feature request related to a problem? Please describe.
I have to manage multiple languages, and my application has turned a bit large. I don't speak 26 languages, so I rely heavily on native speakers or translation agencies. When I want them to help me with my translations, it is better to provide an excel sheet. So nowadays I build excel sheets by stripping the JSON data by hand and with some nice concat functions I reconstruct the JSON, and place it manually into the DEV-STG-UAT and Live environments.
This workflow has no use of the sync-missing-translations artisan command that is most helpfull. So my team now needs to maintian a list of translations in confluence for us to keep track. It is very easy to make mistakes here.
Describe the solution you'd like
I would like to have a export / import functionality to EXCEL sheets with the key in column A and all translations or maybe only the source and target language in columns B and beyond. This way we can ship this to non-coders like regular sales colleagues, secretaries, or translating agencies.
Describe alternatives you've considered
See problem description.
Additional context
I really like your approach on this subject. And your code base looks great and very tidy. So I'll stick with your package and would like to help you take this further.
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'language' cannot be null (SQL: insert into languages
Regards, I tried to install this component in an environment with Laravel 6.0
But unfortunately, it cannot be installed. It marks the following error in the post installation procedure.
> @php artisan package:discover --ansi
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Symfony\Component\Debug\Exception\FatalThrowableError : Class name must be a valid object or a string
at C:\MY_DISK_PATH\vendor\spatie\laravel-translation-loader\src\TranslationServiceProvider.php:51
47| {
48| $this->app->singleton('translation.loader', function ($app) {
49| $class = config('translation-loader.translation_manager');
50|
> 51| return new $class($app['files'], $app['path.lang']);
52| });
53| }
54| }
55|
Adding full transcription of error...
C:\WEBSites\ADMpanel-New>composer require joedixon/laravel-translation
Using version ^1.0 for joedixon/laravel-translation
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing joedixon/laravel-translation (v1.0.1): Loading from cache
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Symfony\Component\Debug\Exception\FatalThrowableError : Class name must be a valid object or a string
at C:\MY_DISK_PATH\vendor\spatie\laravel-translation-loader\src\TranslationServiceProvider.php:51
47| {
48| $this->app->singleton('translation.loader', function ($app) {
49| $class = config('translation-loader.translation_manager');
50|
> 51| return new $class($app['files'], $app['path.lang']);
52| });
53| }
54| }
55|
Exception trace:
1 Spatie\TranslationLoader\TranslationServiceProvider::Spatie\TranslationLoader\{closure}(Object(Illuminate\Foundation\Application), [])
C:\MY_DISK_PATH\vendor\laravel\framework\src\Illuminate\Container\Container.php:800
2 Illuminate\Container\Container::build(Object(Closure))
C:\MY_DISK_PATH\vendor\laravel\framework\src\Illuminate\Container\Container.php:682
Please use the argument -v to see more details.
I understand that I may not be optimized for operation with Laravel 6.0, but I hope you can help me with this error.
The complete configuration of the packages installed on the computer for this project is::
"require": {
"php": "^7.2",
"aws/aws-php-sns-message-validator": "^1.5",
"aws/aws-sdk-php": "^3.67",
"caouecs/laravel-lang": "~3.0",
"defuse/php-encryption": "^2.2",
"fideloper/proxy": "^4.0",
"jenssegers/date": "^3.4",
"joedixon/laravel-translation": "^1.0",
"laracasts/flash": "^3.0",
"laravel/framework": "^6.0",
"laravel/horizon": "^3.2",
"laravel/tinker": "^1.0",
"laravel/ui": "^1.0",
"laravelcollective/remote": "^6.0",
"laraveles/spanish": "^1.4",
"league/flysystem-aws-s3-v3": "^1.0",
"matthewbdaly/laravel-sms": "^1.0",
"neitanod/forceutf8": "^2.0",
"phpseclib/phpseclib": "^2.0",
"shivella/laravel-bitly": "^1.1",
"stichoza/google-translate-php": "^4.0",
"vrkansagara/lara-out-press": "^1.1"
},
"require-dev": {
"facade/ignition": "^1.4",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^8.0"
},
Describe the bug
When i use artisan for generate missing translation keys, this make an invalid key because in my code i have an dynamic translation path.
Currently i have __('games.game.' . $serverInfo->type)
and this generate in main json file :
{
"games.game.' . $serverInfo->type) }}\">\n {!! App\\Helpers\\MinecraftColor::clean($serverInfo->displayName) !!}\n <\/td>\n <td class=\"text-right\">\n @if (isset($serverInfo->status) && $serverInfo->status->state === 'on": ""
}
To Reproduce
Steps to reproduce the behavior:
__('games.' . $game)
Expected behavior
When use php artisan translation:sync-missing-translation-keys
don't generate dynamic path if that could not be parsed.
OR : Create part of path. exemple if my code is __('games.game.' . $game)
, this create the array for games.game
and keep that array empty
Hello, I would love to see 2 things in this packagea.a
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.