/**
* Get a translation message wrapper function for getting JSON Laravel-JS-Localization generated translations
*
* @param key {string} The key of the message.
* @param replacements {object} The replacements to be done in the message.
* @param locale {string} The locale to use, if not passed use the default locale.
*
* @return {string} The translation message, if not found the given key.
*/
Lang.prototype.__ = function(key, replacements, locale) {
const stringsDomain = "strings";
const stringsKey = `${stringsDomain}.${key}`;
const stringTranslation = this.has(stringsKey, locale);
const translation = this.has(key, locale);
if (!stringTranslation && !translation) {
return key;
}
if (translation) {
return this.get(key, replacements, locale);
}
return this.get(stringsKey, replacements, locale);
}
Laravel-JS-Localization generated translations issue
If in folder
lang
are translations injson
files, translations generated by Laravel-JS-Localization looks like:In this case in Laravel provide helper function
__
and as a default value it returns passed argument string. Example:In folder we have only
resources/lang/pl.json
because default behavior of Laravel function return key as default value.Possible solution
Add aditional method
__
for getting translations generated by Laravel-JS-Localization.