Code Monkey home page Code Monkey logo

laravel-localization-helpers's People

Contributors

adriandmitroca avatar ckithika avatar daverdalas avatar liingon avatar limenet avatar mpociot avatar potsky avatar rockkeeper avatar shulard avatar waffle-iron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-localization-helpers's Issues

Controller has no parent

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.

[ErrorException] touch(): Unable to create file .... \lang\de\confide::confide.php because Invalid argument

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.

Auto generated / dynamic keys not 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.

[REQUEST] Show obselete strings when in array

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.

Support fallbacks

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

VCS friendly updates

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.

Refactor

Use objects instead of arrays to handle :

  • lemma
  • lang files

Lemma properties :

  • collection of lang file source object (cyclic definition !)
  • family
  • key
  • value
  • collection of translated value
  • ...

Lang files properties :

  • type (vendor lang, lang or json)
  • collection of language file paths
  • obsolete collection of lemma (cyclic definition !)
  • new collection of lemma (cyclic definition !)
  • already collection of lemma (cyclic definition !)

Update language files but keep the original formatting

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.

Clean obselete, keep existing, add new with default + questions

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.

  • I already have translation file with some good (not obselte) value translated, some good value not translated (empty/null), some obselete value (strings no more in blade templates)
  • I updated my templates with new trans('the.string.code') string

What i need to do is so :

  • Delete obselete string from translation file (no more in template) (only obselete to keep non-obselete already translated strings)
  • Add new template string to file (from template update) with default value
  • Update empty/null string in file with default value

What i was thinking to do :

php 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 :)

Problem with backup when dot is in path

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.

Automatic translations

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.

_ide_helper

Please remove _ide_helper.php from repository as it can interfere with main project's _ide_helper.php

Track multi-line function calls

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.

Laravel 5.3 support

any plan to release it soon ? Or is there any work around to install it in a laravel 5.3 application?

Need help. What is "family"?

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.

[Question] Using dynamic fields

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.

Specific 'Lang' file to ignore

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:

  • ../../de/cms.php
  • ../../en/cms.php
  • ..e.t.c..

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', ) ,

"Unable to write file in directory..."

(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.

Dynamic fields with parameters In language lines

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

Php >= 5.4 array syntax

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.

Laravel 4.2

Can you please add support for Laravel 4.2?

upgrade declarations to Laravel 5.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) {...

When trans() gets an array of strings, the tool thinks it's a missing string

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.

Syntax error in Factory/Localization.php

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

output-flat flag updated behaviour suggestion

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.

Laravel 5 folder structure

Hi,

as Laravel 5 stores the language files in /resources/lang/ the command should be modified to look for this directory too.

Regards,
Marcel

FormRequests are not included

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.

File format compatibility with Transifex

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!!! :)

Case Insensitive searching

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 :)

Build error when trying to install `potsky/microsoft-translator-php-sdk` as dependency

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>]...

Full Build Info

Is there anything I can do from this end to install it successfully?

Thanks in advance!!

Alphabetically sorting the output

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

Dot notation not supported

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?

Keep files if only date time would change

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.

[Question] Generated files coding style

Is there a way to configure coding style?

I mean for having -say- PSR-2 compliant output.

  1. Array declaration syntax array() vs []
  2. Indentation depth

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 :)

laravel/framework as a dependency

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.

Obsolete strings never go back into main array

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 :)

Place holders cause Obsolete string

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.

Question about TODO files in vendor directory

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.