diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en_US.json b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json similarity index 100% rename from extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en_US.json rename to extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-base/src/main/resources/translations/en.json diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/LanguageResourceService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/LanguageResourceService.java index 9710f0ddf..9955b5bf6 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/LanguageResourceService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/extension/LanguageResourceService.java @@ -74,12 +74,15 @@ public class LanguageResourceService { * The regular expression to use for parsing the language key from the * filename. */ - private static final Pattern LANGUAGE_KEY_PATTERN = Pattern.compile(".*/([a-z]+_[A-Z]+)\\.json"); + private static final Pattern LANGUAGE_KEY_PATTERN = Pattern.compile(".*/([a-z]+(_[A-Z]+)?)\\.json"); /** * Map of all language resources by language key. Language keys are * language and country code pairs, separated by an underscore, like - * "en_US". + * "en_US". The country code and underscore SHOULD be omitted in the case + * that only one dialect of that language is defined, or in the case of the + * most universal or well-supported of all supported dialects of that + * language. */ private final Map resources = new HashMap(); diff --git a/guacamole/src/main/webapp/app/index/config/indexTranslationConfig.js b/guacamole/src/main/webapp/app/index/config/indexTranslationConfig.js index c73aa7770..3bc7543a2 100644 --- a/guacamole/src/main/webapp/app/index/config/indexTranslationConfig.js +++ b/guacamole/src/main/webapp/app/index/config/indexTranslationConfig.js @@ -30,7 +30,7 @@ angular.module('index').config(['$injector', function($injector) { var preferenceServiceProvider = $injector.get('preferenceServiceProvider'); // Fallback to US English - var fallbackLanguages = ['en_US']; + var fallbackLanguages = ['en']; // Prefer chosen language, use fallback languages if necessary $translateProvider.fallbackLanguage(fallbackLanguages); diff --git a/guacamole/src/main/webapp/app/locale/services/translationLoader.js b/guacamole/src/main/webapp/app/locale/services/translationLoader.js index b80699e42..7e2ca49bf 100644 --- a/guacamole/src/main/webapp/app/locale/services/translationLoader.js +++ b/guacamole/src/main/webapp/app/locale/services/translationLoader.js @@ -81,6 +81,31 @@ angular.module('locale').factory('translationLoader', ['$injector', function tra }; + /** + * Given a valid language key, returns all possible legal variations of + * that key. Currently, this will be the given key and the given key + * without the country code. If the key has no country code, only the + * given key will be included in the returned array. + * + * @param {String} key + * The language key to generate variations of. + * + * @returns {String[]} + * All possible variations of the given language key. + */ + var getKeyVariations = function getKeyVariations(key) { + + var underscore = key.indexOf('_'); + + // If no underscore, only one possibility + if (underscore === -1) + return [key]; + + // Otherwise, include the lack of country code as an option + return [key, key.substr(0, underscore)]; + + }; + /** * Custom loader function for angular-translate which loads the desired * language file dynamically via HTTP. If the language file cannot be @@ -101,7 +126,7 @@ angular.module('locale').factory('translationLoader', ['$injector', function tra var requestedKey = options.key; // Append fallback languages to requested language - var keys = [requestedKey].concat(options.fallbackLanguages); + var keys = getKeyVariations(requestedKey).concat(options.fallbackLanguages); // Satisfy the translation request satisfyTranslation(translation, requestedKey, keys); diff --git a/guacamole/src/main/webapp/translations/en_US.json b/guacamole/src/main/webapp/translations/en.json similarity index 100% rename from guacamole/src/main/webapp/translations/en_US.json rename to guacamole/src/main/webapp/translations/en.json diff --git a/guacamole/src/main/webapp/translations/fr_FR.json b/guacamole/src/main/webapp/translations/fr.json similarity index 100% rename from guacamole/src/main/webapp/translations/fr_FR.json rename to guacamole/src/main/webapp/translations/fr.json diff --git a/guacamole/src/main/webapp/translations/ru_RU.json b/guacamole/src/main/webapp/translations/ru.json similarity index 100% rename from guacamole/src/main/webapp/translations/ru_RU.json rename to guacamole/src/main/webapp/translations/ru.json