#214: added "angular-i18n" gem, some refactoring

This commit is contained in:
Vokhmin Alexey V 2013-07-19 16:34:55 +04:00
parent 1fb472d416
commit c44b4ffda2
12 changed files with 56 additions and 44 deletions

View File

@ -62,6 +62,7 @@ gem "gemoji", "~> 1.2.1", require: 'emoji/railtie'
gem 'angularjs-rails'
gem 'ng-rails-csrf'
gem 'momentjs-rails'
gem 'angular-i18n', '0.1.1'
group :assets do
gem 'sass-rails', '~> 3.2.5'

View File

@ -58,6 +58,7 @@ GEM
json
ancestry (1.3.0)
activerecord (>= 2.3.14)
angular-i18n (0.1.1)
angularjs-rails (1.0.7)
arel (3.0.2)
attr_encrypted (1.2.1)
@ -408,6 +409,7 @@ DEPENDENCIES
RedCloth
airbrake (~> 3.1.2)
ancestry (~> 1.3.0)
angular-i18n (= 0.1.1)
angularjs-rails
attr_encrypted (= 1.2.1)
better_errors

View File

@ -1,4 +1,4 @@
var RosaABF = angular.module('RosaABF', ['ngResource', 'ng-rails-csrf']);
var RosaABF = angular.module('RosaABF', ['ngResource', 'ng-rails-csrf', 'angular-i18n']);
var DateTimeFormatter = function() {
@ -10,5 +10,17 @@ var DateTimeFormatter = function() {
utc : UtcFormatter
}
}
RosaABF.factory("DateTimeFormatter", DateTimeFormatter);
var LocalesHelper = function($locale) {
var locales = {
'ru' : 'ru-ru',
'en' : 'en-us'
}
return {
setLocale: function(locale) {
$locale.id = locales[locale];
}
}
}
RosaABF.factory("LocalesHelper", ['$locale', LocalesHelper]);

View File

@ -8,7 +8,7 @@ RosaABF.controller('ProjectRefsController', ['$scope', '$http', 'ApiProject', fu
$scope.current_ref = null;
$scope.project_resource = null;
$scope.init = function(project_id, ref) {
$scope.init = function(project_id, ref, locale) {
$scope.project_id = project_id;
$scope.current_ref = ref;
@ -45,6 +45,8 @@ RosaABF.controller('ProjectRefsController', ['$scope', '$http', 'ApiProject', fu
}
$scope
$scope.updateBranchesCount = function() {
$scope.singleton.project.branches_count = $scope.branches.length;
}

View File

@ -0,0 +1,7 @@
RosaABF.controller('RosaABFController', ['$scope', 'LocalesHelper', function($scope, LocalesHelper) {
$scope.init = function(locale) {
LocalesHelper.setLocale(locale);
}
}]);

View File

@ -0,0 +1,24 @@
var _locales = {
'ru-ru': {
'total_branches': [
'Всего %1 ветка',
'Всего %1 ветки',
'Всего %1 веток'
],
'total_tags': [
'Всего %1 тег',
'Всего %1 тега',
'Всего %1 тегов'
]
},
'en-us': {
'total_branches': [
'Total %1 branch',
'Total %1 branches'
],
'total_tags': [
'Total %1 tag',
'Total %1 tags'
]
}
};

View File

@ -19,6 +19,7 @@
// require angular-resource
//= require unstable/angular-resource
//= require ng-rails-csrf
//= require angular-i18n
//= require_tree ./angularjs
//= require moment

View File

@ -12,7 +12,7 @@
- if user_signed_in?
= auto_discovery_link_tag :atom, atom_activity_feeds_path(:format => 'atom', :token => current_user.authentication_token), :title => t("layout.atom_link_tag_title", :nickname => current_user.uname, :app_name => APP_CONFIG['project_name'])
%body{'ng-app' => 'RosaABF'}
%body{'ng-app' => 'RosaABF', 'ng-controller' => 'RosaABFController', 'ng-init' => "init('#{I18n.locale}')"}
.wrap{:class => content_for?(:sidebar) ? 'columns' : ''}
%header
.left

View File

@ -8,13 +8,7 @@
%h3= t('layout.projects.branches')
%p{'ng-show' => '!branches.length'}= t('layout.projects.no_branches')
%p{'ng-show' => 'branches.length == 1'}
= t('layout.projects.total_branches', :count => '{{branches.length}}', :branches => t('layout.projects.pluralize.branches.branch'))
%p{'ng-show' => 'branches.length > 1 && branches.length < 5'}
= t('layout.projects.total_branches', :count => '{{branches.length}}', :branches => t('layout.projects.pluralize.branches.branches2'))
%p{'ng-show' => 'branches.length > 4'}
= t('layout.projects.total_branches', :count => '{{branches.length}}', :branches => t('layout.projects.pluralize.branches.branches'))
%p{'ng-show' => 'branches.length > 0'} {{'total_branches' | i18n:'plural':branches.length}}
.both
%br

View File

@ -7,12 +7,7 @@
%h3= t('layout.projects.tags')
%p{'ng-show' => '!tags.length'}= t('layout.projects.no_tags')
%p{'ng-show' => 'tags.length == 1'}
= t('layout.projects.total_tags', :count => '{{tags.length}}', :tags => t('layout.projects.pluralize.tags.tag'))
%p{'ng-show' => 'tags.length > 1 && tags.length < 5'}
= t('layout.projects.total_tags', :count => '{{tags.length}}', :tags => t('layout.projects.pluralize.tags.tags2'))
%p{'ng-show' => 'tags.length > 4'}
= t('layout.projects.total_tags', :count => '{{tags.length}}', :tags => t('layout.projects.pluralize.tags.tags'))
%p{'ng-show' => 'tags.length > 0'} {{'total_tags' | i18n:'plural':tags.length}}
.both
%br

View File

@ -2,27 +2,14 @@ en:
layout:
projects:
branches: Branches
pluralize:
branches:
branch: branch
branches: branches
branches2: branches
tags:
tag: tag
tags: tags
tags2: tags
delete_branch: Delete branch
restore_branch: Restore branch
total_branches: Total %{count} %{branches}
no_branches: No branches
base_branch: Base branch
compare: Compare
browse_code: Browse code
source_code: Source code (%{type})
tags: Tags
total_tags: Total %{count} %{tags}
no_tags: No tags
add: Add
public_projects_list: Public projects list

View File

@ -2,27 +2,14 @@ ru:
layout:
projects:
branches: Ветки
pluralize:
branches:
branch: ветка
branches: веток
branches2: ветки
tags:
tag: тег
tags: тегов
tags2: тега
delete_branch: Удалить ветку
restore_branch: Востановить ветку
total_branches: Всего %{count} %{branches}
no_branches: Нет веток
base_branch: Текущая ветка
compare: Сравнить
browse_code: Просмотреть код
source_code: Исходный код (%{type})
tags: Теги
total_tags: Всего %{count} %{tags}
no_tags: Нет тегов
add: Добавить
public_projects_list: Список публичных проектов