potsky / laravel-localization-helpers Goto Github PK
View Code? Open in Web Editor NEW๐ Artisan commands to generate and update lang files automatically
License: GNU General Public License v3.0
๐ Artisan commands to generate and update lang files automatically
License: GNU General Public License v3.0
Hi,
Please elaborate the error below:
action not allowed in file /app/controllers/NameOfController.php will not be included because it has no parent
Thanks.
Hi, your tool works great, but I have a problem with some packages that have their translation files in the vendor folder.
For example with confide.
This is in a view:
{{{ Lang::get('confide::confide.password') }}}
And when I use the command, I get this error:
45 lemmas have been found in code
Scan files:
\app\lang\de\confide::confide.php
> File has been created
[ErrorException]
touch(): Unable to create file..... \app\lang\de\confide::confide.php because Invalid argument
So I pointed to a folder with views without confide and it's working.
In your config file is the option for never_obsolete_keys
and your example for this option.
But when we have something like
trans("app.sections.$section->id")
this lemma is never found at all. So setting sections
as a key in never_obsolete_keys
has no effect because the inital lemma wasn't found.
Would be great to show obselete strings when they are nested in an array.
We have something like
return array (
'buttons' => [
'save' => 'Save',
'change' => 'Change',
]
);
So if the key app.buttons.change
is obsolete, your package recognizes this, prints it in the command line interface (1 obsolete strings (can be deleted manually in the generated file)) and when the file is created, nothing shows up after the obsolete strings section (comment).
If it isn't possible or easy to specially mark the obsolete strings directly in the array, it would be great to output the specific keys in the obsolete strings section. In that case we could search the found keys ourselves in the arrays and remove them.
Hey @potsky,
What do you think about idea that accept null values as a translations? This approach would allow you to use translations fallbacks - because you probably want to display english translation to the user instead of something like TODO: hello_user
This could be possible using a custom parameter like:
php artisan localization:missing -l null
or php artisan localization:missing --support-fallbacks
Hey @potsky,
It would be nice to update translations without changing content of basically whole translation's file. In this situation, when you create new translation string you don't commit change with bunch of changed lines but just with one insert.
Use objects instead of arrays to handle :
Lemma properties :
Lang files properties :
So the point is, if dedicated setting is on, the script would scan the file, look for things like new line before array opening, keys notation, tabulation, etc. Then it would add missing lemmas in proper places, mark them with "TODO:" label, mark obsolete translations with "OBSOLETE:" label etc. That would keep original style of the file, all the comments etc, yet make maintenance of translations a breeze.
I am aware that this sounds like a big change, with difficult implementation. Anyway I though I may share this idea, as others may like it and fint it useful.
Decent solution shouldn't actually take that much time and may be good enough for many people.
Some time ago I've written similar command for syncing translations between languages, you may check it out here. Feel free to integrate it in the package if you consider it useful or modify it however you like!
I hope we may see this feature implemented one day. I'm eager to help with the development if you think this is a good idea. I might even try to code it all by myself, however before I'd like to hear some feedback.
Hey there,
thanks for the cool package. Seems really helpful, and i cant wait to get it working.
This is not an issue, but i would like some advices on the way to make what i need.
trans('the.string.code')
stringphp artisan localization:missing -o -l "TODO: %LEMMA"
To find new translated string and set a default value + delete obselete ones (no more in templates)
Does it will also set null/empty translated string to the default value ?
As i see php artisan localization:missing -l 'Please translate this !'
set all lemma values to "Please translate this !"
And use the ":missing" parameter so maybe...
Thanks a lot :)
Refer to #52 for the regex dot notation split feature
We have a DOCUMENT_ROOT structure where the domain name is part of the path. For example: /var/www/kd/domain.com/
When the command :missing is backup'ing the files, we get an Error Exception because the path is incorrect and the permission is denied. The path generated by your script (preg_match) is like:
/var/www/kd/domain.20160129_151020.php
So i propose to change the generation of the backup directory with keeping in mind that there could be a doc root with a dot in the path.
How is the automatic translations option working?
Looking in the code, we guess it's taking the last part of the "lemma" and translates it to a specific language, taking the default_language
from the config.
Is it possible to define the default_language
where everything is already translated and translate the values of the "lemmas" to the values of the "lemmas" of the other languages? So we could give all the right translations in our own native language and translate it to the languages we would like to use in our project.
Please remove _ide_helper.php from repository as it can interfere with main project's _ide_helper.php
Hey,
I found that this package has some serious issue when you call trans()
function like this:
trans('user.welcome', [
'name' => $user->name
]);
Situation like this is tracked like obsolete string or is not tracked at all. It works just fine when parameters are passed in the same line.
any plan to release it soon ? Or is there any work around to install it in a laravel 5.3 application?
in https://github.com/potsky/laravel-localization-helpers/blob/5.0/composer.json
you have:
"require": {
"friendsofphp/php-cs-fixer": "^1.11",
shouldn't that be moved to require-dev?
Hi,
when i try to run php artisan localization:missing i got an error like that:
[BadMethodCallException] Call to undefined method [package]
it looks like the package() method was deleted from src/Illuminate/Config/Repository.php in this commit:
Can you fix ?
i heard microsoft plan to end subscription for datamarket and dataservice on 3/31/2017 and migrate to their new Cognitive Service
https://datamarket.azure.com/dataset/bing/microsofttranslator
is there any plan to integrate with it ?
I ran localization:missing
and got messages like that
New account in file \resources\views\accounts\create.blade.php will not be included because it has no family
What is the family?
Strings in my blades are like:
@lang('New account')
Strings in my controllers are like:
echo trans(
'Created :createdCount. Updated :updatedCount',
compact('createdCount', 'updatedCount')
);
Please help me.
By updating a project composer claims:
Package fabpot/php-cs-fixer is abandoned, you should avoid using it. Use friendsofphp/php-cs-fixer instead.
I'm using the following technique to load dynamic translations like so:
trans('appointments.status.'.$appointment->statusLabel)
return array (
//==================================== Translations ====================================//
'text' =>
array (
'minutes' => 'minutes',
'to' => 'to',
'duration' => 'duration',
),
//================================== Obsolete strings ==================================//
'alert' =>
array (
'annulated' => 'Advice! Reservation was ANNULATED',
),
'status' =>
array (
'annulated' => 'Annulated',
'confirmed' => 'Confirmed',
'reserved' => 'Reserved',
'served' => 'Served',
),
);
I've seen I can avoid them getting into Obsolete by naming the key like trans('appointments.status.dynamic.'.$appointment->statusLabel)
for which I'd use a translation like so:
return array (
//==================================== Translations ====================================//
'text' =>
array (
'minutes' => 'minutes',
'to' => 'to',
'duration' => 'duration',
),
//================================== Obsolete strings ==================================//
'alert' =>
array (
'annulated' => 'Advice! Reservation was ANNULATED',
),
'status' => array ( 'dynamic' =>
array (
'annulated' => 'Annulated',
'confirmed' => 'Confirmed',
'reserved' => 'Reserved',
'served' => 'Served',
),
),
);
But after running php artisan localization:missing
the set does not appear at all, either in Obsolete or Translated sections.
Am I missing anything about how to use the command? Have you got any suggestions?
Thank you in advance!
You can find the project here to see other cases where I'm using this approach.
I think all you need to do is change the illuminate/support from 5.4.* to 5.5.*
In Laravel 5.1.x / 2.2.4
In laravel-localization-helpers.php is an array in which developer can specify which language file will be ignored.
Language files:
So if someone would want to filter only one cms.php under de/cms.php and would want all the other cms.php translation files to be untouched, then some additional conditions would have to be implemented.
specific file ignore Example:
'ignore_lang_files' => array( 'validation' , '/resources/lang/de/cms.php', ) ,
It seems every trans key I use that involves a replacement associative array gets marked as obsolete.
(I am a beginner, bear with my silly questions please)
Hi,
I am running php artisan localization:missing, lemmas are being found in my views (I use trans()), but I ma getting the following message: "> Unable to write file in directory /home/vagrant/Code/fitl/resources/lang/en/shared". So no lang files are being created in target language subfolders. As you can tell, my app is on a Homestead virtual machine.
Thanks for your help.
Maybe this is more of a question, somewhat referencing issue #53
I am still getting the same error when running localization:missing command but on a different line
My directive is this:
@lang('pages/master/home.offers.message.' . session("message"), ['membership' => url('membership')])
And my translation file looks like this:
'offers' => array(
'message' => array(
'login' => 'You need to login first.',
'premium' => 'You need to change your membership to premium. If you want to know more, click <a class="btn-link" target="_blank" href=":membership">here</a> to find out.',
'card' => 'You can use your member card for this offer.'
)
),
Then I added message to the never_obsolete_keys array
'never_obsolete_keys' => array(
'dynamic',
'fields',
'message',
) ,
And the error_log gives this output:
'pages/master/home.offers.dynamic.message.' . session("message"), ['membership' => url('membership'
PHP ParseError: syntax error, unexpected ',', expecting ';' in /var/www/html/local.familiando/vendor/potsky/laravel-localization-helpers/src/Potsky/LaravelLocalizationHelpers/Factory/Localization.php(559) : eval()'d code on line 1
Hey,
are you planning to migrate your microsoft-translator api towards azure?
Would be amazing! I totally love the -t for some basic translation!
Regards,
Freddy
It would be nice if the exported arrays would use the new syntax for arrays. I know var_export still uses array() notation, but I found this http://stackoverflow.com/a/24316457 and it seems to be working in my tests.
If it's ok for you I could create a pull request with it.
Can you please add support for Laravel 4.2?
By trying to upgrade to L5.2 artisan clear-compiled
returns errors like this
Declaration of Potsky\LaravelLocalizationHelpers\Commands\LocalizationAbstract::info()
should be compatible with Illuminate\Console\Command::info($string, $verbosity = NULL)
The errors can be fixed by changing declarations to:
public function line( $s , $style = NULL, $verbosity = NULL) {...
public function info( $s , $verbosity = NULL) {...
public function comment( $s , $verbosity = NULL ) {...
public function question( $s , $verbosity = NULL) {...
First, thanks for an awesome tool! It's made my life a lot easier.
I ran into a minor issue. Assume there's a translation file called things.php
:
'foo' => [
'bar' => 'bar',
'baz' => 'baz',
]
Then, somewhere, there's a call to trans('things.foo')
and uses the resulting array. When I run the artisan command in dry-run mode, it thinks that things.foo
is a missing string.
Hi, I'm using Laravel v5.2.45, it could be I'm missing something, basically I followed the installation instructions and when I try to run any of the localization commands I get this error
syntax error, unexpected ';', expecting ',' or ')' in /var/www/html/local.familiando/vendor/potsky/laravel-localization-helpers/src/Potsky/LaravelLocalizationHelpers/Factory/Localization.php(323) : eval()'d code on line 1
Hi,
I'm just wondering will this package support Laravel's JSON translation system?
Thanks.
Hi,
I am normally translating strings in the format __('labels.my long string'), where "my long string" on occasions contains periods.
Although the -w flag properly flattens the (supposed) array structure, the translation value ends up being the segment after the last period (LocalizationMissing, line 377).
Is this normal or it would be better to have something like the following at that line:
if ( $this->option( 'output-flat' ) ) {
$key_last_token = [$key];
} else {
$key_last_token = explode('.', $key);
}
This would ensure that a translation of 'labels.Loading records...', for example, will have "Loading records..." as translation value.
If you think that 'output-flat''s behaviour should remain unchanged, then maybe a new flag for this could be added?
Thank you!
EDIT: already know what you're about to say - this special use case is not the intended use for output-flat and you're right. I am actually using too phrases in which it's ok to have the last segment as translation.
Yet, there are exceptions like the ones above. I am thinking that maybe we could use a special array config with keys which will don't get the explode treatment?
Added a pull request for this.
Hi,
as Laravel 5 stores the language files in /resources/lang/
the command should be modified to look for this directory too.
Regards,
Marcel
This package doesn't search for translation strings in Http/Requests
.
Scenario:
When you are forced to write custom validation message for specified Form Requests, you override messages() method and write messages there. For example:
public function messages()
{
return [
'exists' => trans('password.E-mail doesn't exist in our database.')
];
}
Issue: This string isn't catched by localization:missing
console command.
Hi @potsky ,
I was wondering if the helpers would generate Transifex-compatible files (not a privative format, but they require certain syntax specifications).
I've used the helpers from the very beginning to generate my base lang files, and since I'm willing to use Transifex for the child lang branches, I'm handling this task to see if a file syntax conversion is worth.
Unfortunately, I don't feel the current lang taxonomy I'm using is actualy good (I feel I currently got too many nested array levels) (my research on this), but I'm either willing to use a big flat array file, and here comes laravel-localization-helpers into play.
Recap: I'd like to use laravel-localization-helpers for generating a base lang file from views that can easily be ported to Transifex for the child lang branches. (Yes, maybe I'm willing to regenerate all my files over)
I appreciate your comments and alternative ideas if any!!! :)
This is a little nitpick-y, It took me a couple minutes to realize it can't find
Lang::get('main.home')
but CAN find
Lang::Get('main.home')
The Laravel docs use the lowercase in their example, might be worth including both :)
It should be useful to have support this library https://github.com/rmariuzzo/Laravel-JS-Localization
In fact, php artisan localization:missing
considers as obsolete translation strings even if in JS files.
Hi,
I'm getting a Travis build error when trying to install potsky/microsoft-translator-php-sdk
as dependency of potsky/laravel-localization-helpers
.
The error is as follows.
- Installing potsky/microsoft-translator-php-sdk (v0.0.2)
Downloading: Connecting... Failed to download potsky/microsoft-translator-php-sdk from dist: Could not authenticate against github.com
Now trying to download from source
- Installing potsky/microsoft-translator-php-sdk (v0.0.2)
Cloning f0d17b1b8716376dabc9a028f1c8e78523ac7e7f
f0d17b1b8716376dabc9a028f1c8e78523ac7e7f is gone (history was rewritten?)
[RuntimeException]
Failed to execute git checkout 'f0d17b1b8716376dabc9a028f1c8e78523ac7e7f' -
- && git reset --hard 'f0d17b1b8716376dabc9a028f1c8e78523ac7e7f' --
fatal: reference is not a tree: f0d17b1b8716376dabc9a028f1c8e78523ac7e7f
install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...
Is there anything I can do from this end to install it successfully?
Thanks in advance!!
Hey,
I'm using the localization helpers quite a lot - thank you for your work!
Would it be possible to sort the output of the arrays by it's key? I think it's currently sorted by the time the string appears in a file.
Regards,
Marcel
If i have
'product' => 'Product',
'product.name' => 'Name',
'product.price' => 'Price',
after localization:missing
i'll get
'product' => array(
'name' => 'Name',
'price' => 'Price',
),
As you can see the first keyword is lost. Would it be possible to support dot notation, maybe through an option?
I've got a number of projects with a lot of languages and several translation files. Whenever I update them, I get a ton of changes, most of them only get a new header info Generated via "php artisan localization:missing" at 2016/03/07 15:19:58
.
Do you have any reason why we shouldn't ignore those files completely? I'd suggest to keep the previous date time to avoid having unnecessary long commit logs.
Is there a way to configure coding style?
I mean for having -say- PSR-2 compliant output.
array()
vs []
I know there might not be a way to change this by parameter, but I cannot either figure out where to change that in the code. I may raise a PR otherwise :)
It should not
I'm using this package with Lumen. But because laravel/framework is specified as a dependency, it pulls the entire framework on composer install
. I was wondering, maybe you can you limit the dependencies to separate Illuminate packages.
Hi !
I don't know if this is voluntary or not but if you decide to use obsolete strings that have already been translated and call a localization:missing, the command will end up with Drink a Piรฑa colada and/or smoke Super Skunk, you have nothing to do!
IMHO, the problem is the strings still remain in obsolete array and are not moved back into the main array.
That's more a thought than an issue but I think it could be useful if you were able to do it in both ways.
Have a nice day :)
Just playing around with this tonight and found using place holders causes the strings to be listed as obsolete. The below string, emails.failed_job_message comes back as obsolete when it obviously exists.
trans('emails.failed_job_message', ['id' => $job->getJobId(), 'jobData' => $job->getRawBody()])
Checked out a few other files where I use place holders and they were returned as well. This is when using Laravel 4. I've not checked whether it occurs on my other Laravel 5 site.
When localization:missing command, there are files generated and placed in the lang/vendor directory. Many of these look like this:
//============================== New strings to translate ==============================//
// Defined in file /vagrant/biospex/resources/views/frontend/projects/show.blade.php
'advertise' => 'TODO: advertise',
// Defined in file /vagrant/biospex/resources/views/frontend/projects/show.blade.php
'advertiseTitle' => 'TODO: advertiseTitle',
Which refers to this:
<button title="@lang('buttons.advertiseTitle')" class="btn btn-success btn-sm" type="button"
onClick="location.href='{{ route('web.advertises.index', [$project->id]) }}'"><span
class="fa fa-globe fa-lrg"></span> @lang('buttons.advertise')</button>
And is clearly present in the lang/en/buttons.php file that is generated:
//==================================== Translations ====================================//
'advertise' => 'Advertise',
'advertiseTitle' => 'Advertise this project in external websites',
So, I'm wondering why this is telling me I have a TODO when it already exists?
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.