Merge pull request #474 from acran/master
Some minor fixes/updates to i18n
This commit is contained in:
commit
f5ff2bdb92
@ -51,17 +51,14 @@ angular.module('myApp.filters', ['myApp.i18n'])
|
|||||||
}
|
}
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.filter('dateOrTime', ['$filter', '_', function($filter, _) {
|
.filter('dateOrTime', ['$filter', function($filter) {
|
||||||
var cachedDates = {},
|
var cachedDates = {},
|
||||||
dateFilter = $filter('date');
|
dateFilter = $filter('date');
|
||||||
|
|
||||||
return function (timestamp) {
|
return function (timestamp) {
|
||||||
if (!cachedDates.hasOwnProperty(_.locale())) {
|
|
||||||
cachedDates[_.locale()] = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cachedDates[_.locale()][timestamp]) {
|
if (cachedDates[timestamp]) {
|
||||||
return cachedDates[_.locale()][timestamp];
|
return cachedDates[timestamp];
|
||||||
}
|
}
|
||||||
|
|
||||||
var ticks = timestamp * 1000,
|
var ticks = timestamp * 1000,
|
||||||
@ -74,42 +71,34 @@ angular.module('myApp.filters', ['myApp.i18n'])
|
|||||||
else if (diff > 43200000) { // 12 hours
|
else if (diff > 43200000) { // 12 hours
|
||||||
format = 'EEE';
|
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 = {},
|
var cachedDates = {},
|
||||||
dateFilter = $filter('date'),
|
dateFilter = $filter('date'),
|
||||||
format = Config.Mobile ? 'HH:mm' : 'HH:mm:ss';
|
format = Config.Mobile ? 'HH:mm' : 'HH:mm:ss';
|
||||||
|
|
||||||
return function (timestamp) {
|
return function (timestamp) {
|
||||||
if (!cachedDates.hasOwnProperty(_.locale())) {
|
if (cachedDates[timestamp]) {
|
||||||
cachedDates[_.locale()] = {};
|
return cachedDates[timestamp];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cachedDates[_.locale()][timestamp]) {
|
return cachedDates[timestamp] = dateFilter(timestamp * 1000, format);
|
||||||
return cachedDates[_.locale()][timestamp];
|
|
||||||
}
|
|
||||||
|
|
||||||
return cachedDates[_.locale()][timestamp] = dateFilter(timestamp * 1000, format);
|
|
||||||
}
|
}
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.filter('myDate', ['$filter', '_', function($filter, _) {
|
.filter('myDate', ['$filter', function($filter) {
|
||||||
var cachedDates = {},
|
var cachedDates = {},
|
||||||
dateFilter = $filter('date');
|
dateFilter = $filter('date');
|
||||||
|
|
||||||
return function (timestamp) {
|
return function (timestamp) {
|
||||||
if (!cachedDates.hasOwnProperty(_.locale())) {
|
if (cachedDates[timestamp]) {
|
||||||
cachedDates[_.locale()] = {};
|
return cachedDates[timestamp];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cachedDates[_.locale()][timestamp]) {
|
return cachedDates[timestamp] = dateFilter(timestamp * 1000, 'fullDate');
|
||||||
return cachedDates[_.locale()][timestamp];
|
|
||||||
}
|
|
||||||
|
|
||||||
return cachedDates[_.locale()][timestamp] = dateFilter(timestamp * 1000, 'fullDate');
|
|
||||||
}
|
}
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
defaultLocale = 'en-us',
|
defaultLocale = 'en-us',
|
||||||
bootReady = {
|
bootReady = {
|
||||||
dom: false,
|
dom: false,
|
||||||
i18n_ng: Config.I18n.locale == defaultLocale, // Already included
|
i18n_ng: locale == defaultLocale, // Already included
|
||||||
i18n_messages: false,
|
i18n_messages: false,
|
||||||
i18n_fallback: false
|
i18n_fallback: false
|
||||||
},
|
},
|
||||||
@ -114,13 +114,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!bootReady.i18n_ng) {
|
if (!bootReady.i18n_ng) {
|
||||||
$('head').append($('<script>')
|
$('<script>').appendTo('head')
|
||||||
.on('load', function() {
|
.on('load', function() {
|
||||||
bootReady.i18n_ng = true;
|
bootReady.i18n_ng = true;
|
||||||
checkReady();
|
checkReady();
|
||||||
})
|
})
|
||||||
.attr('src', 'vendor/angular/i18n/angular-locale_' + Config.I18n.locale + '.js')
|
.attr('src', 'vendor/angular/i18n/angular-locale_' + Config.I18n.locale + '.js');
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$.getJSON('js/locales/' + Config.I18n.locale + '.json').success(function (json) {
|
$.getJSON('js/locales/' + Config.I18n.locale + '.json').success(function (json) {
|
||||||
@ -145,4 +144,4 @@
|
|||||||
checkReady();
|
checkReady();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
@ -50,7 +50,8 @@ Config.I18n = {
|
|||||||
'es-es': 'Español'
|
'es-es': 'Español'
|
||||||
},
|
},
|
||||||
aliases: {
|
aliases: {
|
||||||
'en': 'en-us'
|
'en': 'en-us',
|
||||||
|
'de': 'de-de'
|
||||||
},
|
},
|
||||||
messages: {},
|
messages: {},
|
||||||
fallback_messages: {}
|
fallback_messages: {}
|
||||||
|
@ -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).
|
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`
|
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
|
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!
|
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/).
|
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>.
|
|||||||
Including html markup in the messages directly isn't supported and any contained markup will be escaped before inserting.
|
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
|
#### 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 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`.
|
||||||
The key for this is the locale string while the value is the name of the language to be displayed in the settings.
|
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 select input and can be used.
|
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.
|
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 `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:
|
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
|
```javascript
|
||||||
var aliases = {
|
Config.I18n.aliases= {
|
||||||
'en': 'en-us'
|
'en': 'en-us'
|
||||||
};
|
}
|
||||||
```
|
```
|
||||||
This maps a `navigator.language == 'en'` to `en-us` as locale to use.
|
This maps a `navigator.language == 'en'` to `en-us` as locale to use.
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@
|
|||||||
"confirm_modal_forward_to_peer": "An {peer} weiterleiten?",
|
"confirm_modal_forward_to_peer": "An {peer} weiterleiten?",
|
||||||
"confirm_modal_send_to_peer": "An {peer} senden?",
|
"confirm_modal_send_to_peer": "An {peer} senden?",
|
||||||
"confirm_modal_share_file_peer": "Mit {peer} teilen?",
|
"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_are_u_sure": "Bist du sicher?",
|
||||||
"confirm_modal_logout_submit": "Abmelden",
|
"confirm_modal_logout_submit": "Abmelden",
|
||||||
"confirm_modal_history_flush_submit": "Chat löschen",
|
"confirm_modal_history_flush_submit": "Chat löschen",
|
||||||
|
@ -718,7 +718,7 @@ angular.module('myApp.services', ['myApp.i18n'])
|
|||||||
|
|
||||||
var messagesStorage = {};
|
var messagesStorage = {};
|
||||||
var messagesForHistory = {};
|
var messagesForHistory = {};
|
||||||
var messagesForDialogs = {locale: _.locale()};
|
var messagesForDialogs = {};
|
||||||
var historiesStorage = {};
|
var historiesStorage = {};
|
||||||
var dialogsStorage = {count: null, dialogs: []};
|
var dialogsStorage = {count: null, dialogs: []};
|
||||||
var pendingByRandomID = {};
|
var pendingByRandomID = {};
|
||||||
@ -1736,10 +1736,6 @@ angular.module('myApp.services', ['myApp.i18n'])
|
|||||||
function wrapForDialog (msgID, unreadCount) {
|
function wrapForDialog (msgID, unreadCount) {
|
||||||
var useCache = unreadCount != -1;
|
var useCache = unreadCount != -1;
|
||||||
|
|
||||||
if (messagesForDialogs.locale != _.locale()) {
|
|
||||||
messagesForDialogs = {locale: _.locale()};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (useCache && messagesForDialogs[msgID] !== undefined) {
|
if (useCache && messagesForDialogs[msgID] !== undefined) {
|
||||||
return messagesForDialogs[msgID];
|
return messagesForDialogs[msgID];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user