We have moved to Github. Please open tickets there.

Opened 15 months ago

Last modified 13 months ago

#4390 new Defect

js elgg_echo doesn't fall back to default translation

Reported by: coldtrick Owned by:
Priority: normal Milestone: Near Term Future Release
Component: Core Version: 1.8.3
Severity: critical Keywords: translation, elgg_echo
Cc: brett@… Difficulty:

Description (last modified by ewinslow)

Only the current user language is js loaded in js/lib/languages. Also the elgg.elgg_echo is not falling back to site language when user language key is not found.

This situation is very irritating when you are using a lot of elgg_echo's in js and have your site in a different language than "en"

I provide a quick fix here, but maybe cash can consider this in his translations caching system.


elgg.config.translations.init = function() {
	elgg.reload_all_translations();
	if(elgg.get_language() !== elgg.config.language){
		elgg.reload_all_translations(elgg.config.language);
	}
};

and

elgg.echo = function(key, argv, language) {
	//elgg.echo('str', 'en')
	if (elgg.isString(argv)) {
		language = argv;
		argv = [];
	}

	//elgg.echo('str', [...], 'en')
	var translations = elgg.config.translations,
		dlang = elgg.get_language(),
		map;

	language = language || dlang;
	argv = argv || [];

	map = translations[language] || translations[dlang];
	if (map && map[key]) {
		return vsprintf(map[key], argv);
	}
	if(dlang !== elgg.config.language){
		map = translations[elgg.config.language];
		if (map && map[key]) {
			return vsprintf(map[key], argv);
		}
	}

	return key;
};

Change History (3)

comment:1 Changed 15 months ago by coldtrick

Also a fix in the reload_all_translation function is needed to prevent a duplicate init.

elgg.reload_all_translations = function(language) {
	var lang = language || elgg.get_language();

	var url, options;
	if (elgg.config.simplecache_enabled) {
		url = 'cache/js/default/languages/' + lang + '.' + elgg.config.lastcache + '.js';
		options = {};
	} else {
		url = 'ajax/view/js/languages';
		options = {data: {language: lang}};
	}

	options['success'] = function(json) {
		elgg.add_translation(lang, json);
		if(elgg.config.languageReady !== true){
			elgg.config.languageReady = true;
			elgg.initWhenReady();
		}
	};

	elgg.getJSON(url, options);
};

comment:2 Changed 15 months ago by coldtrick

Better to pull the initWhenReady out of the reload function...

comment:3 Changed 13 months ago by ewinslow

  • Description modified (diff)
  • Milestone changed from Needs Review to Near Term Future Release

requirejs would make all of this so much easier...

Note: See TracTickets for help on using tickets.