Browse Source

integrated i18n in all modules

every string in the modules to be displayed should now be passed through
`_` first
master
Roman Anasal 10 years ago
parent
commit
e28e47eae5
  1. 19
      app/js/controllers.js
  2. 24
      app/js/directives.js
  3. 42
      app/js/filters.js
  4. 2
      app/js/lib/config.js
  5. 40
      app/js/services.js

19
app/js/controllers.js

@ -23,7 +23,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
ChangelogNotifyService.checkUpdate(); ChangelogNotifyService.checkUpdate();
}) })
.controller('AppLoginController', function ($scope, $rootScope, $location, $timeout, $modal, $modalStack, MtpApiManager, ErrorService, NotificationsManager, ChangelogNotifyService, IdleManager) { .controller('AppLoginController', function ($scope, $rootScope, $location, $timeout, $modal, $modalStack, MtpApiManager, ErrorService, NotificationsManager, ChangelogNotifyService, IdleManager, _) {
$modalStack.dismissAll(); $modalStack.dismissAll();
IdleManager.start(); IdleManager.start();
@ -96,10 +96,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
for (i = 0; i < Config.CountryCodes.length; i++) { for (i = 0; i < Config.CountryCodes.length; i++) {
country = Config.CountryCodes[i]; country = Config.CountryCodes[i];
if (country[0] == countryIso2) { if (country[0] == countryIso2) {
return selectCountry({name: country[1], code: country[2]}); return selectCountry({name: _(country[1] + '_raw'), code: country[2]});
} }
} }
return selectCountry({name: 'United States', code: '+1'}); return selectCountry({name: _('country_select_modal_country_us_raw'), code: '+1'});
} }
function selectCountry (country) { function selectCountry (country) {
@ -130,7 +130,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
code = Config.CountryCodes[i][j].replace(/\D+/g, ''); code = Config.CountryCodes[i][j].replace(/\D+/g, '');
if (code.length > maxLength && !phoneNumber.indexOf(code)) { if (code.length > maxLength && !phoneNumber.indexOf(code)) {
maxLength = code.length; maxLength = code.length;
maxName = Config.CountryCodes[i][1]; maxName = _(Config.CountryCodes[i][1] + '_raw');
} }
} }
} }
@ -138,7 +138,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} }
$scope.credentials.phone_full = phoneNumber; $scope.credentials.phone_full = phoneNumber;
$scope.credentials.phone_country_name = maxName || 'Unknown'; $scope.credentials.phone_country_name = maxName || _('login_controller_unknown_country_raw');
}; };
$scope.$watch('credentials.phone_country', updateCountry); $scope.$watch('credentials.phone_country', updateCountry);
@ -2492,7 +2492,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}) })
.controller('CountrySelectModalController', function ($scope, $modalInstance, $rootScope, SearchIndexManager) { .controller('CountrySelectModalController', function ($scope, $modalInstance, $rootScope, SearchIndexManager, _) {
$scope.search = {}; $scope.search = {};
$scope.slice = {limit: 20, limitDelta: 20} $scope.slice = {limit: 20, limitDelta: 20}
@ -2500,7 +2500,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
var searchIndex = SearchIndexManager.createIndex(); var searchIndex = SearchIndexManager.createIndex();
for (var i = 0; i < Config.CountryCodes.length; i++) { for (var i = 0; i < Config.CountryCodes.length; i++) {
SearchIndexManager.indexObject(i, Config.CountryCodes[i].join(' '), searchIndex); var searchString = Config.CountryCodes[i][0];
searchString += ' ' + _(Config.CountryCodes[i][1] + '_raw');
searchString += ' ' + Config.CountryCodes[i].slice(2).join(' ');
SearchIndexManager.indexObject(i, searchString, searchIndex);
} }
$scope.$watch('search.query', function (newValue) { $scope.$watch('search.query', function (newValue) {
@ -2519,7 +2522,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
for (var i = 0; i < Config.CountryCodes.length; i++) { for (var i = 0; i < Config.CountryCodes.length; i++) {
if (!filtered || results[i]) { if (!filtered || results[i]) {
for (j = 2; j < Config.CountryCodes[i].length; j++) { for (j = 2; j < Config.CountryCodes[i].length; j++) {
$scope.countries.push({name: Config.CountryCodes[i][1], code: Config.CountryCodes[i][j]}); $scope.countries.push({name: _(Config.CountryCodes[i][1] + '_raw'), code: Config.CountryCodes[i][j]});
} }
} }
} }

24
app/js/directives.js

@ -844,7 +844,7 @@ angular.module('myApp.directives', ['myApp.filters'])
}) })
.directive('mySendForm', function ($timeout, $modalStack, Storage, ErrorService) { .directive('mySendForm', function ($timeout, $modalStack, Storage, ErrorService, $interpolate) {
return { return {
link: link, link: link,
@ -868,7 +868,7 @@ angular.module('myApp.directives', ['myApp.filters'])
if (richTextarea) { if (richTextarea) {
editorElement = richTextarea; editorElement = richTextarea;
$(richTextarea).addClass('form-control'); $(richTextarea).addClass('form-control');
$(richTextarea).attr('placeholder', $(messageField).attr('placeholder')); $(richTextarea).attr('placeholder', $interpolate($(messageField).attr('placeholder'))($scope));
var updatePromise; var updatePromise;
$(richTextarea) $(richTextarea)
@ -1198,7 +1198,7 @@ angular.module('myApp.directives', ['myApp.filters'])
}) })
.directive('myLoadFullPhoto', function(MtpApiFileManager) { .directive('myLoadFullPhoto', function(MtpApiFileManager, _) {
return { return {
link: link, link: link,
@ -1263,9 +1263,13 @@ angular.module('myApp.directives', ['myApp.filters'])
$scope.progress.enabled = false; $scope.progress.enabled = false;
if (e && e.type == 'FS_BROWSER_UNSUPPORTED') { if (e && e.type == 'FS_BROWSER_UNSUPPORTED') {
$scope.error = {html: 'Your browser doesn\'t support <a href="https://developer.mozilla.org/en-US/docs/Web/API/LocalFileSystem" target="_blank">LocalFileSystem</a> feature which is needed to display this image.<br/>Please, install <a href="http://google.com/chrome" target="_blank">Google Chrome</a> or use <a href="https://telegram.org/" target="_blank">mobile app</a> instead.'}; $scope.error = {html: _('browser_no_local_file_system_image', {
'moz-link': '<a href="{0}" target="_blank">{1}</a>',
'chrome-link': '<a href="{0}" target="_blank">{1}</a>',
'telegram-link': '<a href="{0}" target="_blank">{1}</a>'
})};
} else { } else {
$scope.error = {text: 'Download failed', error: e}; $scope.error = {text: _('error_image_download_failed'), error: e};
} }
}, function (progress) { }, function (progress) {
$scope.progress.percent = Math.max(1, Math.floor(100 * progress.done / progress.total)); $scope.progress.percent = Math.max(1, Math.floor(100 * progress.done / progress.total));
@ -1277,7 +1281,7 @@ angular.module('myApp.directives', ['myApp.filters'])
}) })
.directive('myLoadVideo', function($sce, MtpApiFileManager) { .directive('myLoadVideo', function($sce, MtpApiFileManager, _) {
return { return {
link: link, link: link,
@ -1323,9 +1327,13 @@ angular.module('myApp.directives', ['myApp.filters'])
$scope.player.src = ''; $scope.player.src = '';
if (e && e.type == 'FS_BROWSER_UNSUPPORTED') { if (e && e.type == 'FS_BROWSER_UNSUPPORTED') {
$scope.error = {html: 'Your browser doesn\'t support <a href="https://developer.mozilla.org/en-US/docs/Web/API/LocalFileSystem" target="_blank">LocalFileSystem</a> feature which is needed to play this video.<br/>Please, install <a href="http://google.com/chrome" target="_blank">Google Chrome</a> or use <a href="https://telegram.org/" target="_blank">mobile app</a> instead.'}; $scope.error = {html: _('error_browser_no_local_file_system_video', {
'moz-link': '<a href="{0}" target="_blank">{1}</a>',
'chrome-link': '<a href="{0}" target="_blank">{1}</a>',
'telegram-link': '<a href="{0}" target="_blank">{1}</a>'
})};
} else { } else {
$scope.error = {text: 'Video download failed', error: e}; $scope.error = {text: _('error_video_download_failed'), error: e};
} }
}, function (progress) { }, function (progress) {

42
app/js/filters.js

@ -11,41 +11,41 @@
angular.module('myApp.filters', ['myApp.i18n']) angular.module('myApp.filters', ['myApp.i18n'])
.filter('userName', [function() { .filter('userName', ['_', function(_) {
return function (user) { return function (user) {
if (!user || !user.first_name && !user.last_name) { if (!user || !user.first_name && !user.last_name) {
return 'DELETED'; return _('user_name_deleted');
} }
return user.first_name + ' ' + user.last_name; return user.first_name + ' ' + user.last_name;
} }
}]) }])
.filter('userFirstName', [function() { .filter('userFirstName', ['_', function(_) {
return function (user) { return function (user) {
if (!user || !user.first_name && !user.last_name) { if (!user || !user.first_name && !user.last_name) {
return 'DELETED'; return _('user_first_name_deleted');
} }
return user.first_name || user.last_name; return user.first_name || user.last_name;
} }
}]) }])
.filter('userStatus', ['$filter', function($filter) { .filter('userStatus', ['$filter', '_', function($filter, _) {
return function (user) { return function (user) {
if (!user || !user.status || user.status._ == 'userStatusEmpty') { if (!user || !user.status || user.status._ == 'userStatusEmpty') {
return 'offline'; return _('user_status_offline');
} }
if (user.status._ == 'userStatusOnline') { if (user.status._ == 'userStatusOnline') {
return 'online'; return _('user_status_online');
} }
return 'last seen ' + $filter('relativeTime')(user.status.was_online); return _('user_status_last_seen', $filter('relativeTime')(user.status.was_online));
} }
}]) }])
.filter('chatTitle', [function() { .filter('chatTitle', ['_', function(_) {
return function (chat) { return function (chat) {
if (!chat || !chat.title) { if (!chat || !chat.title) {
return 'DELETED'; return _('chat_title_deleted');
} }
return chat.title; return chat.title;
} }
@ -153,7 +153,7 @@ angular.module('myApp.filters', ['myApp.i18n'])
} }
}]) }])
.filter('formatSizeProgress', ['$filter', function ($filter) { .filter('formatSizeProgress', ['$filter', '_', function ($filter, _) {
return function (progress) { return function (progress) {
var done = $filter('formatSize')(progress.done), var done = $filter('formatSize')(progress.done),
doneParts = done.split(' '), doneParts = done.split(' '),
@ -161,9 +161,9 @@ angular.module('myApp.filters', ['myApp.i18n'])
totalParts = total.split(' '); totalParts = total.split(' ');
if (totalParts[1] === doneParts[1]) { if (totalParts[1] === doneParts[1]) {
return doneParts[0] + ' of ' + totalParts[0] + ' ' + (doneParts[1] || ''); return _('format_size_progress_mulitple', {done: done, total: total, parts: (doneParts[1] || '')});
} }
return done + ' of ' + total; return _('format_size_progress', {done: done, total: total});
} }
}]) }])
@ -179,29 +179,29 @@ angular.module('myApp.filters', ['myApp.i18n'])
} }
}]) }])
.filter('relativeTime', ['$filter', function($filter) { .filter('relativeTime', ['$filter', '_', function($filter, _) {
var langMinutes = { var langMinutes = {
one: 'minute ago', one: 'relative_time_one_minute',
many: 'minutes ago' many: 'relative_time_many_minutes'
}, },
langHours = { langHours = {
one: 'hour ago', one: 'relative_time_one_hour',
many: 'hours ago' many: 'relative_time_many_hours'
}; };
return function (timestamp) { return function (timestamp) {
var ticks = timestamp * 1000, var ticks = timestamp * 1000,
diff = Math.abs(tsNow() - ticks); diff = Math.abs(tsNow() - ticks);
if (diff < 60000) { if (diff < 60000) {
return 'just now'; return _('relative_time_just_now');
} }
if (diff < 3000000) { if (diff < 3000000) {
var minutes = Math.ceil(diff / 60000); var minutes = Math.ceil(diff / 60000);
return minutes + ' ' + langMinutes[minutes > 1 ? 'many' : 'one']; return _(langMinutes[minutes > 1 ? 'many' : 'one'], {minutes: minutes});
} }
if (diff < 10000000) { if (diff < 10000000) {
var hours = Math.ceil(diff / 3600000); var hours = Math.ceil(diff / 3600000);
return hours + ' ' + langHours[hours > 1 ? 'many' : 'one']; return _(langHours[hours > 1 ? 'many' : 'one'], {hours: hours});
} }
return $filter('dateOrTime')(timestamp); return $filter('dateOrTime')(timestamp);
} }

2
app/js/lib/config.js

File diff suppressed because one or more lines are too long

40
app/js/services.js

@ -11,7 +11,7 @@
angular.module('myApp.services', ['myApp.i18n']) angular.module('myApp.services', ['myApp.i18n'])
.service('AppUsersManager', function ($rootScope, $modal, $modalStack, $filter, $q, MtpApiFileManager, MtpApiManager, RichTextProcessor, SearchIndexManager, ErrorService, Storage) { .service('AppUsersManager', function ($rootScope, $modal, $modalStack, $filter, $q, MtpApiFileManager, MtpApiManager, RichTextProcessor, SearchIndexManager, ErrorService, Storage, _) {
var users = {}, var users = {},
cachedPhotoLocations = {}, cachedPhotoLocations = {},
contactsFillPromise, contactsFillPromise,
@ -92,8 +92,8 @@ angular.module('myApp.services', ['myApp.i18n'])
apiUser.rFirstName = RichTextProcessor.wrapRichText(apiUser.first_name, {noLinks: true, noLinebreaks: true}); apiUser.rFirstName = RichTextProcessor.wrapRichText(apiUser.first_name, {noLinks: true, noLinebreaks: true});
apiUser.rFullName = RichTextProcessor.wrapRichText(apiUser.first_name + ' ' + (apiUser.last_name || ''), {noLinks: true, noLinebreaks: true}); apiUser.rFullName = RichTextProcessor.wrapRichText(apiUser.first_name + ' ' + (apiUser.last_name || ''), {noLinks: true, noLinebreaks: true});
} else { } else {
apiUser.rFirstName = RichTextProcessor.wrapRichText(apiUser.last_name, {noLinks: true, noLinebreaks: true}) || apiUser.rPhone || 'DELETED'; apiUser.rFirstName = RichTextProcessor.wrapRichText(apiUser.last_name, {noLinks: true, noLinebreaks: true}) || apiUser.rPhone || _('user_first_name_deleted');
apiUser.rFullName = RichTextProcessor.wrapRichText(apiUser.last_name, {noLinks: true, noLinebreaks: true}) || apiUser.rPhone || 'DELETED'; apiUser.rFullName = RichTextProcessor.wrapRichText(apiUser.last_name, {noLinks: true, noLinebreaks: true}) || apiUser.rPhone || _('user_name_deleted');
} }
apiUser.sortName = SearchIndexManager.cleanSearchText(apiUser.first_name + ' ' + (apiUser.last_name || '')); apiUser.sortName = SearchIndexManager.cleanSearchText(apiUser.first_name + ' ' + (apiUser.last_name || ''));
apiUser.sortStatus = apiUser.status && (apiUser.status.expires || apiUser.status.was_online) || 0; apiUser.sortStatus = apiUser.status && (apiUser.status.expires || apiUser.status.was_online) || 0;
@ -456,7 +456,7 @@ angular.module('myApp.services', ['myApp.i18n'])
if (!angular.isObject(apiChat)) { if (!angular.isObject(apiChat)) {
return; return;
} }
apiChat.rTitle = RichTextProcessor.wrapRichText(apiChat.title, {noLinks: true, noLinebreaks: true}) || 'DELETED'; apiChat.rTitle = RichTextProcessor.wrapRichText(apiChat.title, {noLinks: true, noLinebreaks: true}) || _('chat_title_deleted');
if (chats[apiChat.id] === undefined) { if (chats[apiChat.id] === undefined) {
chats[apiChat.id] = apiChat; chats[apiChat.id] = apiChat;
} else { } else {
@ -1835,7 +1835,7 @@ angular.module('myApp.services', ['myApp.i18n'])
case 'messageActionChatCreate': case 'messageActionChatCreate':
case 'messageActionChatEditTitle': case 'messageActionChatEditTitle':
message.action.rTitle = RichTextProcessor.wrapRichText(message.action.title, {noLinks: true, noLinebreaks: true}) || 'DELETED'; message.action.rTitle = RichTextProcessor.wrapRichText(message.action.title, {noLinks: true, noLinebreaks: true}) || _('chat_title_deleted');
break; break;
} }
} }
@ -1946,25 +1946,25 @@ angular.module('myApp.services', ['myApp.i18n'])
notificationMessage = RichTextProcessor.wrapPlainText(message.message); notificationMessage = RichTextProcessor.wrapPlainText(message.message);
} else if (message.media && message.media._ != 'messageMediaEmpty') { } else if (message.media && message.media._ != 'messageMediaEmpty') {
switch (message.media._) { switch (message.media._) {
case 'messageMediaPhoto': notificationMessage = 'Photo'; break; case 'messageMediaPhoto': notificationMessage = _('conversation_media_photo'); break;
case 'messageMediaVideo': notificationMessage = 'Video'; break; case 'messageMediaVideo': notificationMessage = _('conversation_media_video'); break;
case 'messageMediaDocument': notificationMessage = 'Document'; break; case 'messageMediaDocument': notificationMessage = _('conversation_media_document'); break;
case 'messageMediaAudio': notificationMessage = 'Voice message'; break; case 'messageMediaAudio': notificationMessage = _('conversation_media_audio'); break;
case 'messageMediaGeo': notificationMessage = 'Location'; break; case 'messageMediaGeo': notificationMessage = _('conversation_media_location'); break;
case 'messageMediaContact': notificationMessage = 'Contact'; break; case 'messageMediaContact': notificationMessage = _('conversation_media_contact'); break;
default: notificationMessage = 'Attachment'; break; default: notificationMessage = _('conversation_media_attachment'); break;
} }
} else if (message._ == 'messageService') { } else if (message._ == 'messageService') {
switch (message.action._) { switch (message.action._) {
case 'messageActionChatCreate': notificationMessage = 'created the group'; break; case 'messageActionChatCreate': notificationMessage = _('conversation_group_created'); break;
case 'messageActionChatEditTitle': notificationMessage = 'changed group name'; break; case 'messageActionChatEditTitle': notificationMessage = _('conversation_group_renamed'); break;
case 'messageActionChatEditPhoto': notificationMessage = 'changed group photo'; break; case 'messageActionChatEditPhoto': notificationMessage = _('conversation_group_photo_updated'); break;
case 'messageActionChatDeletePhoto': notificationMessage = 'removed group photo'; break; case 'messageActionChatDeletePhoto': notificationMessage = _('conversation_group_photo_removed'); break;
case 'messageActionChatAddUser': case 'messageActionChatAddUser':
notificationMessage = message.action.user_id == message.from_id ? 'returned to group' : 'invited user'; notificationMessage = message.action.user_id == message.from_id ? _('conversation_returned_to_group') : _('conversation_invited_user_message');
break; break;
case 'messageActionChatDeleteUser': case 'messageActionChatDeleteUser':
notificationMessage = message.action.user_id == message.from_id ? 'left group' : 'kicked user'; notificationMessage = message.action.user_id == message.from_id ? _('conversation_left_group') : _('conversation_kicked_user_message');
break; break;
} }
} }
@ -1979,9 +1979,9 @@ angular.module('myApp.services', ['myApp.i18n'])
peerString = AppUsersManager.getUserString(peerID); peerString = AppUsersManager.getUserString(peerID);
} else { } else {
notification.title = (fromUser.first_name || fromUser.last_name || 'Somebody') + notification.title = (fromUser.first_name || fromUser.last_name || _('conversation_unknown_user')) +
' @ ' + ' @ ' +
(AppChatsManager.getChat(-peerID).title || 'Unknown chat'); (AppChatsManager.getChat(-peerID).title || _('conversation_unknown_chat'));
notificationPhoto = AppChatsManager.getChatPhoto(-peerID, 'Group'); notificationPhoto = AppChatsManager.getChatPhoto(-peerID, 'Group');

Loading…
Cancel
Save