From 47f963cbbf7c8bfdbcc7968b2c028a5c0ac939fe Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Fri, 19 Sep 2014 17:26:57 +0200 Subject: [PATCH 1/5] updated german locale: added new message --- app/js/locales/de-de.json | 1 + 1 file changed, 1 insertion(+) diff --git a/app/js/locales/de-de.json b/app/js/locales/de-de.json index 2edcb9ca..fc149f59 100644 --- a/app/js/locales/de-de.json +++ b/app/js/locales/de-de.json @@ -104,6 +104,7 @@ "confirm_modal_forward_to_peer": "An {peer} weiterleiten?", "confirm_modal_send_to_peer": "An {peer} senden?", "confirm_modal_share_file_peer": "Mit {peer} teilen?", + "confirm_modal_apply_lang_with_reload_md": "Spracheinstellungen wurden gespeichert.\nAnwendung jetzt neustarten?", "confirm_modal_are_u_sure": "Bist du sicher?", "confirm_modal_logout_submit": "Abmelden", "confirm_modal_history_flush_submit": "Chat löschen", From c2656c1b299e3f3fc272b331d71660a3337c6fe3 Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Fri, 19 Sep 2014 17:53:43 +0200 Subject: [PATCH 2/5] Revert "put current locale in consideration for various caches in filters/services" This reverts commit 37bb69a409e2ed721def80c69e7727572bfdc17d. Since we moved i18n into the init phase in f1db5e1c962e458cc5da787cf8c248ebe23294f8 and don't switch locale at runtime we don't need this anymore --- app/js/filters.js | 35 ++++++++++++----------------------- app/js/services.js | 6 +----- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/app/js/filters.js b/app/js/filters.js index deb26185..e5f55662 100644 --- a/app/js/filters.js +++ b/app/js/filters.js @@ -51,17 +51,14 @@ angular.module('myApp.filters', ['myApp.i18n']) } }]) - .filter('dateOrTime', ['$filter', '_', function($filter, _) { + .filter('dateOrTime', ['$filter', function($filter) { var cachedDates = {}, dateFilter = $filter('date'); return function (timestamp) { - if (!cachedDates.hasOwnProperty(_.locale())) { - cachedDates[_.locale()] = {}; - } - if (cachedDates[_.locale()][timestamp]) { - return cachedDates[_.locale()][timestamp]; + if (cachedDates[timestamp]) { + return cachedDates[timestamp]; } var ticks = timestamp * 1000, @@ -74,42 +71,34 @@ angular.module('myApp.filters', ['myApp.i18n']) else if (diff > 43200000) { // 12 hours format = 'EEE'; } - return cachedDates[_.locale()][timestamp] = dateFilter(ticks, format); + return cachedDates[timestamp] = dateFilter(ticks, format); } }]) - .filter('time', ['$filter', '_', function($filter, _) { + .filter('time', ['$filter', function($filter) { var cachedDates = {}, dateFilter = $filter('date'), format = Config.Mobile ? 'HH:mm' : 'HH:mm:ss'; return function (timestamp) { - if (!cachedDates.hasOwnProperty(_.locale())) { - cachedDates[_.locale()] = {}; - } - - if (cachedDates[_.locale()][timestamp]) { - return cachedDates[_.locale()][timestamp]; + if (cachedDates[timestamp]) { + return cachedDates[timestamp]; } - return cachedDates[_.locale()][timestamp] = dateFilter(timestamp * 1000, format); + return cachedDates[timestamp] = dateFilter(timestamp * 1000, format); } }]) - .filter('myDate', ['$filter', '_', function($filter, _) { + .filter('myDate', ['$filter', function($filter) { var cachedDates = {}, dateFilter = $filter('date'); return function (timestamp) { - if (!cachedDates.hasOwnProperty(_.locale())) { - cachedDates[_.locale()] = {}; - } - - if (cachedDates[_.locale()][timestamp]) { - return cachedDates[_.locale()][timestamp]; + if (cachedDates[timestamp]) { + return cachedDates[timestamp]; } - return cachedDates[_.locale()][timestamp] = dateFilter(timestamp * 1000, 'fullDate'); + return cachedDates[timestamp] = dateFilter(timestamp * 1000, 'fullDate'); } }]) diff --git a/app/js/services.js b/app/js/services.js index 97d6489c..cad86470 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -718,7 +718,7 @@ angular.module('myApp.services', ['myApp.i18n']) var messagesStorage = {}; var messagesForHistory = {}; - var messagesForDialogs = {locale: _.locale()}; + var messagesForDialogs = {}; var historiesStorage = {}; var dialogsStorage = {count: null, dialogs: []}; var pendingByRandomID = {}; @@ -1736,10 +1736,6 @@ angular.module('myApp.services', ['myApp.i18n']) function wrapForDialog (msgID, unreadCount) { var useCache = unreadCount != -1; - if (messagesForDialogs.locale != _.locale()) { - messagesForDialogs = {locale: _.locale()}; - } - if (useCache && messagesForDialogs[msgID] !== undefined) { return messagesForDialogs[msgID]; } From f878dbd96f37d3c649415ce80a28c3c072174181 Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Fri, 19 Sep 2014 18:08:42 +0200 Subject: [PATCH 3/5] updated i18n guide reflect changes of f1db5e1c962e458cc5da787cf8c248ebe23294f8 --- app/js/locales/Readme.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/js/locales/Readme.md b/app/js/locales/Readme.md index b9cf32c2..a09fe9e1 100644 --- a/app/js/locales/Readme.md +++ b/app/js/locales/Readme.md @@ -7,7 +7,7 @@ Adding a new locale is pretty easy, all you got to do is: 1. ensure that the angular-locale file `vendor/angular/i18n/angular-locale_.js` exists. If not copy one of the others being most similar to your target locale and adapt it accordingly. See also the [angular docs](https://docs.angularjs.org/guide/i18n). 2. copy `js/locales/en-us.json` to `js/locales/.json` 3. without changing the key strings translate and change the value strings into your target locale -4. add your locale in js/i18n.js to the object of supported languages with locale and its native name so it will be listed in the settings +4. add your locale to `Config.I18n` in `js/lib/config.js` with locale and its native name so it will be listed in the settings 5. enjoy your awesome new Webogram in your own language! You may also want to join the project on [transifex](https://www.transifex.com/projects/p/telegram-web/). @@ -65,16 +65,16 @@ This is an unofficial web-client for the Telegram Messenger. Including html markup in the messages directly isn't supported and any contained markup will be escaped before inserting. #### Step 4: adding the newly created locale -The final step is to add the new locale to the list with supported (i.e. existing) locales for webogram in the factory of the localization function `_` in `js/i18n.js`. -The key for this is the locale string while the value is the name of the language to be displayed in the settings. -After adding to the list (and perhaps restarting the app) it appears in the select input and can be used. +The final step is to add the new locale to the list with supported (i.e. existing) locales for Webogram in `Config.I18n` object in `js/lib/config.js`. +Add the locale to the `Config.I18n.supported` array and to `Config.I18n.languages` with the locale as key and the native name of the language as value. +After adding to the list (and perhaps restarting the app) it appears in the footer. -Additionally you can add your locale to the `aliases` object. This object is used when there is no locale configured yet and we're trying to guess the best fit from the browsers current language. -Since we're retrieving the browser language through `navigator.language` which may contain a locale with or without country code, we use `aliases` here to map between these and our supported locales whereby the keys are the lookup values and the values a locale we support, e.g: +Additionally you can add your locale to `Config.I18n.aliases`. This object is used when there is no locale configured yet and we're trying to guess the best fit from the browsers current language. +Since we're retrieving the browser language through `navigator.language` which may contain a locale with or without country code, we use `Config.I18n.aliases` here to map between these and our supported locales whereby the keys are the lookup values and the values a locale we support, e.g: ```javascript -var aliases = { +Config.I18n.aliases= { 'en': 'en-us' -}; +} ``` This maps a `navigator.language == 'en'` to `en-us` as locale to use. From ace380f2bbf474e5868add97941dc45f48919df3 Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Fri, 19 Sep 2014 18:21:12 +0200 Subject: [PATCH 4/5] added alias 'de' for 'de-de' --- app/js/lib/config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/js/lib/config.js b/app/js/lib/config.js index df575bc9..d1dcc502 100644 --- a/app/js/lib/config.js +++ b/app/js/lib/config.js @@ -50,7 +50,8 @@ Config.I18n = { 'es-es': 'Español' }, aliases: { - 'en': 'en-us' + 'en': 'en-us', + 'de': 'de-de' }, messages: {}, fallback_messages: {} From 4f317b4282e21b650e55ba9920a5df5297411684 Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Fri, 19 Sep 2014 20:09:42 +0200 Subject: [PATCH 5/5] fix loading of angular-locale in init.js 1. check for locale == defaultLocale for locale from ConfigStorage 2. the