#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 'angularjs-rails'
gem 'ng-rails-csrf' gem 'ng-rails-csrf'
gem 'momentjs-rails' gem 'momentjs-rails'
gem 'angular-i18n', '0.1.1'
group :assets do group :assets do
gem 'sass-rails', '~> 3.2.5' gem 'sass-rails', '~> 3.2.5'

View File

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

View File

@ -1,14 +1,26 @@
var RosaABF = angular.module('RosaABF', ['ngResource', 'ng-rails-csrf']); var RosaABF = angular.module('RosaABF', ['ngResource', 'ng-rails-csrf', 'angular-i18n']);
var DateTimeFormatter = function() { var DateTimeFormatter = function() {
var UtcFormatter = function(api_time) { var UtcFormatter = function(api_time) {
return moment.utc(api_time * 1000).format('YYYY-MM-DD HH:mm:ss UTC'); return moment.utc(api_time * 1000).format('YYYY-MM-DD HH:mm:ss UTC');
} }
return { return {
utc : UtcFormatter utc : UtcFormatter
} }
} }
RosaABF.factory("DateTimeFormatter", DateTimeFormatter);
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.current_ref = null;
$scope.project_resource = null; $scope.project_resource = null;
$scope.init = function(project_id, ref) { $scope.init = function(project_id, ref, locale) {
$scope.project_id = project_id; $scope.project_id = project_id;
$scope.current_ref = ref; $scope.current_ref = ref;
@ -45,6 +45,8 @@ RosaABF.controller('ProjectRefsController', ['$scope', '$http', 'ApiProject', fu
} }
$scope
$scope.updateBranchesCount = function() { $scope.updateBranchesCount = function() {
$scope.singleton.project.branches_count = $scope.branches.length; $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 angular-resource
//= require unstable/angular-resource //= require unstable/angular-resource
//= require ng-rails-csrf //= require ng-rails-csrf
//= require angular-i18n
//= require_tree ./angularjs //= require_tree ./angularjs
//= require moment //= require moment

View File

@ -12,7 +12,7 @@
- if user_signed_in? - 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']) = 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' : ''} .wrap{:class => content_for?(:sidebar) ? 'columns' : ''}
%header %header
.left .left

View File

@ -8,13 +8,7 @@
%h3= t('layout.projects.branches') %h3= t('layout.projects.branches')
%p{'ng-show' => '!branches.length'}= t('layout.projects.no_branches') %p{'ng-show' => '!branches.length'}= t('layout.projects.no_branches')
%p{'ng-show' => 'branches.length == 1'} %p{'ng-show' => 'branches.length > 0'} {{'total_branches' | i18n:'plural':branches.length}}
= 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'))
.both .both
%br %br

View File

@ -7,12 +7,7 @@
%h3= t('layout.projects.tags') %h3= t('layout.projects.tags')
%p{'ng-show' => '!tags.length'}= t('layout.projects.no_tags') %p{'ng-show' => '!tags.length'}= t('layout.projects.no_tags')
%p{'ng-show' => 'tags.length == 1'} %p{'ng-show' => 'tags.length > 0'} {{'total_tags' | i18n:'plural':tags.length}}
= 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'))
.both .both
%br %br

View File

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

View File

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