potsky / laravel-localization-helpers

🎌 Artisan commands to generate and update lang files automatically
GNU General Public License v3.0
187 stars 38 forks source link

output-flat flag updated behaviour suggestion #51

Closed schniper closed 7 years ago

schniper commented 7 years ago

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.

potsky commented 7 years ago

See #52