Browse Source

Merge pull request #474 from acran/master

Some minor fixes/updates to i18n
master
Igor Zhukov 10 years ago
parent
commit
f5ff2bdb92
  1. 35
      app/js/filters.js
  2. 17
      app/js/init.js
  3. 3
      app/js/lib/config.js
  4. 16
      app/js/locales/Readme.md
  5. 1
      app/js/locales/de-de.json
  6. 6
      app/js/services.js

35
app/js/filters.js

@ -51,17 +51,14 @@ angular.module('myApp.filters', ['myApp.i18n']) @@ -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']) @@ -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');
}
}])

17
app/js/init.js

@ -78,7 +78,7 @@ @@ -78,7 +78,7 @@
defaultLocale = 'en-us',
bootReady = {
dom: false,
i18n_ng: Config.I18n.locale == defaultLocale, // Already included
i18n_ng: locale == defaultLocale, // Already included
i18n_messages: false,
i18n_fallback: false
},
@ -114,13 +114,12 @@ @@ -114,13 +114,12 @@
}
if (!bootReady.i18n_ng) {
$('head').append($('<script>')
.on('load', function() {
bootReady.i18n_ng = true;
checkReady();
})
.attr('src', 'vendor/angular/i18n/angular-locale_' + Config.I18n.locale + '.js')
);
$('<script>').appendTo('head')
.on('load', function() {
bootReady.i18n_ng = true;
checkReady();
})
.attr('src', 'vendor/angular/i18n/angular-locale_' + Config.I18n.locale + '.js');
}
$.getJSON('js/locales/' + Config.I18n.locale + '.json').success(function (json) {
@ -145,4 +144,4 @@ @@ -145,4 +144,4 @@
checkReady();
});
});
})();
})();

3
app/js/lib/config.js

@ -50,7 +50,8 @@ Config.I18n = { @@ -50,7 +50,8 @@ Config.I18n = {
'es-es': 'Español'
},
aliases: {
'en': 'en-us'
'en': 'en-us',
'de': 'de-de'
},
messages: {},
fallback_messages: {}

16
app/js/locales/Readme.md

@ -7,7 +7,7 @@ Adding a new locale is pretty easy, all you got to do is: @@ -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_<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/<locale>.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 <strong>Telegram Messenger</strong>. @@ -65,16 +65,16 @@ This is an unofficial web-client for the <strong>Telegram Messenger</strong>.
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.

1
app/js/locales/de-de.json

@ -104,6 +104,7 @@ @@ -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",

6
app/js/services.js

@ -718,7 +718,7 @@ angular.module('myApp.services', ['myApp.i18n']) @@ -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']) @@ -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];
}

Loading…
Cancel
Save