thiagocordeiro/laravel-translator

Translation as Default Value

alexandresg opened this issue · 7 comments

Is it possible to assign a default value to the translation somehow? Maybe a flag (suggestion: "useKeysAsDefaultValue")?

Laravel, for example, gives us the option to use keys instead of the translation itself, as keys of the JSON translation files. Because of this, libraries which automatically translate JSON files relies in the value, not the key, to then generate automatically translated files (https://github.com/fkirc/attranslate as an example).

I did not found any setting which would allow me to have the Translation as both, key and default value, so i could then use this JSON file as an entry point to generate the localised JSON's in other languages.

TL:DR
Is it possible to have a flag which allows me to generate a JSON:
{ "First Message Translated": "First Message Translated", "Second Message Translated": "Second Message Translated", "Third Message Translated": "Third Message Translated", }

Instead of the current:
{ "First Message Translated": "", "Second Message Translated": "", "Third Message Translated": "", }

Thanks @alexandresg for the suggestion.

For sure it's possible, it would require us to configure a default language, because we don't want to set the value on a different language rather than the default.

Bellow an idea of the new configuration file:

return [
    'languages' => ['en', 'pt-br', 'es'],
    'defaultLanguage' => 'en',
    'useKeysAsDefaultValue' => true, // requires default language to be set, will fill the values on the default language
    ...
];

@thiagocordeiro that sounds great, yes, i would much appreciate that functionality.

Also, thanks for your work on this package. It's very helpful.

@alexandresg awesome, I'll work on this improvements in the upcoming weeks ;)

Was this concept ever worked out? We're interested in the same use-case :)

@mbardelmeijer sure thing, I can work on it but I'm kinda busy right now, would you mind sumitting a PR?

I believe you could change LaravelJsonTranslationRepository.php to check whether the language is the default one and value is empty at line 48

@thiagocordeiro no problem! Had finally some time to take a shot. See #50

Fixes on version 1.2.2