socialcast-i18n-js 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/README.md +324 -0
- data/README.rdoc +320 -0
- data/Rakefile +13 -0
- data/app/assets/javascripts/i18n/translations.js.erb +6 -0
- data/app/assets/javascripts/i18n.js +661 -0
- data/config/i18n-js.yml +22 -0
- data/i18n-js.gemspec +28 -0
- data/lib/i18n/js/engine.rb +6 -0
- data/lib/i18n/js/file_dependency_processor.rb +17 -0
- data/lib/i18n/js/railtie.rb +17 -0
- data/lib/i18n/js/translator.rb +56 -0
- data/lib/i18n/js/version.rb +10 -0
- data/lib/i18n-js/engine.rb +63 -0
- data/lib/i18n-js/middleware.rb +59 -0
- data/lib/i18n-js/railtie.rb +13 -0
- data/lib/i18n-js/rake.rb +16 -0
- data/lib/i18n-js/version.rb +10 -0
- data/lib/i18n-js.rb +22 -0
- data/lib/tasks/i18n-js.rake +17 -0
- data/spec/file_dependency_processor_spec.rb +32 -0
- data/spec/fixtures/custom_path.yml +2 -0
- data/spec/fixtures/default.yml +2 -0
- data/spec/fixtures/js_file_per_locale.yml +1 -0
- data/spec/fixtures/locales.yml +76 -0
- data/spec/fixtures/multiple_conditions.yml +3 -0
- data/spec/fixtures/no_config.yml +2 -0
- data/spec/fixtures/simple_scope.yml +2 -0
- data/spec/i18n_js_spec.rb +11 -0
- data/spec/i18n_spec.js +820 -0
- data/spec/i18n_spec.rb +205 -0
- data/spec/js/currency.spec.js +60 -0
- data/spec/js/current_locale.spec.js +19 -0
- data/spec/js/dates.spec.js +218 -0
- data/spec/js/defaults.spec.js +23 -0
- data/spec/js/interpolation.spec.js +28 -0
- data/spec/js/jasmine/MIT.LICENSE +20 -0
- data/spec/js/jasmine/jasmine-html.js +190 -0
- data/spec/js/jasmine/jasmine.css +166 -0
- data/spec/js/jasmine/jasmine.js +2476 -0
- data/spec/js/jasmine/jasmine_favicon.png +0 -0
- data/spec/js/localization.spec.js +41 -0
- data/spec/js/numbers.spec.js +124 -0
- data/spec/js/placeholder.spec.js +24 -0
- data/spec/js/pluralization.spec.js +105 -0
- data/spec/js/prepare_options.spec.js +41 -0
- data/spec/js/specs.html +46 -0
- data/spec/js/translate.spec.js +119 -0
- data/spec/js/translations.js +115 -0
- data/spec/resources/custom_path.yml +4 -0
- data/spec/resources/default.yml +4 -0
- data/spec/resources/js_file_per_locale.yml +3 -0
- data/spec/resources/locales.yml +76 -0
- data/spec/resources/multiple_conditions.yml +6 -0
- data/spec/resources/multiple_files.yml +6 -0
- data/spec/resources/no_config.yml +2 -0
- data/spec/resources/no_scope.yml +3 -0
- data/spec/resources/simple_scope.yml +4 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/translator_spec.rb +45 -0
- data/vendor/assets/javascripts/i18n/translations.js.erb +9 -0
- data/vendor/assets/javascripts/i18n.js +531 -0
- data/vendor/assets/javascripts/underscore.js +1059 -0
- metadata +240 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
en:
|
2
|
+
number:
|
3
|
+
format:
|
4
|
+
separator: "."
|
5
|
+
delimiter: ","
|
6
|
+
precision: 3
|
7
|
+
currency:
|
8
|
+
format:
|
9
|
+
format: "%u%n"
|
10
|
+
unit: "$"
|
11
|
+
separator: "."
|
12
|
+
delimiter: ","
|
13
|
+
precision: 2
|
14
|
+
date:
|
15
|
+
formats:
|
16
|
+
default: "%Y-%m-%d"
|
17
|
+
short: "%b %d"
|
18
|
+
long: "%B %d, %Y"
|
19
|
+
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
|
20
|
+
abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
|
21
|
+
month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
|
22
|
+
abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
|
23
|
+
# order: [ :year, :month, :day ]
|
24
|
+
time:
|
25
|
+
formats:
|
26
|
+
default: "%a, %d %b %Y %H:%M:%S %z"
|
27
|
+
short: "%d %b %H:%M"
|
28
|
+
long: "%B %d, %Y %H:%M"
|
29
|
+
am: "am"
|
30
|
+
pm: "pm"
|
31
|
+
admin:
|
32
|
+
show:
|
33
|
+
title: "Show"
|
34
|
+
note: "more details"
|
35
|
+
edit:
|
36
|
+
title: "Edit"
|
37
|
+
|
38
|
+
fr:
|
39
|
+
date:
|
40
|
+
formats:
|
41
|
+
default: "%d/%m/%Y"
|
42
|
+
short: "%e %b"
|
43
|
+
long: "%e %B %Y"
|
44
|
+
long_ordinal: "%e %B %Y"
|
45
|
+
only_day: "%e"
|
46
|
+
day_names: [dimanche, lundi, mardi, mercredi, jeudi, vendredi, samedi]
|
47
|
+
abbr_day_names: [dim, lun, mar, mer, jeu, ven, sam]
|
48
|
+
month_names: [~, janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre]
|
49
|
+
abbr_month_names: [~, jan., fév., mar., avr., mai, juin, juil., août, sept., oct., nov., déc.]
|
50
|
+
# order: [ :day, :month, :year ]
|
51
|
+
time:
|
52
|
+
formats:
|
53
|
+
default: "%d %B %Y %H:%M"
|
54
|
+
time: "%H:%M"
|
55
|
+
short: "%d %b %H:%M"
|
56
|
+
long: "%A %d %B %Y %H:%M:%S %Z"
|
57
|
+
long_ordinal: "%A %d %B %Y %H:%M:%S %Z"
|
58
|
+
only_second: "%S"
|
59
|
+
am: 'am'
|
60
|
+
pm: 'pm'
|
61
|
+
number:
|
62
|
+
format:
|
63
|
+
precision: 3
|
64
|
+
separator: ','
|
65
|
+
delimiter: ' '
|
66
|
+
currency:
|
67
|
+
format:
|
68
|
+
unit: '€'
|
69
|
+
precision: 2
|
70
|
+
format: '%n %u'
|
71
|
+
admin:
|
72
|
+
show:
|
73
|
+
title: "Visualiser"
|
74
|
+
note: "plus de détails"
|
75
|
+
edit:
|
76
|
+
title: "Editer"
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "i18n"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
require "active_support/all"
|
5
|
+
require "i18n-js"
|
6
|
+
|
7
|
+
module Helpers
|
8
|
+
# Set the configuration as the current one
|
9
|
+
def set_config(path)
|
10
|
+
config = HashWithIndifferentAccess.new(YAML.load_file(File.dirname(__FILE__) + "/fixtures/#{path}"))
|
11
|
+
I18n::Js.stub(:config? => true, :config => config)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Shortcut to I18n::Js.translations
|
15
|
+
def translations
|
16
|
+
I18n::Js::Translator.translations
|
17
|
+
end
|
18
|
+
|
19
|
+
def file_should_exist(name)
|
20
|
+
file_path = File.join(I18n::Js.export_dir, name)
|
21
|
+
File.should be_file(file_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def temp_path(file_name = "")
|
25
|
+
File.expand_path("../../tmp/i18n-js/#{file_name}", __FILE__)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
RSpec.configure do |config|
|
30
|
+
config.before do
|
31
|
+
I18n.load_path = [File.dirname(__FILE__) + "/fixtures/locales.yml"]
|
32
|
+
FileUtils.rm_rf(temp_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
config.after do
|
36
|
+
FileUtils.rm_rf(temp_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
config.include Helpers
|
40
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require 'i18n/js/translator'
|
3
|
+
|
4
|
+
describe I18n::Js::Translator do
|
5
|
+
context "#filter" do
|
6
|
+
it "filters translations using scope *.date.formats" do
|
7
|
+
result = I18n::Js::Translator.filter(translations, "*.date.formats")
|
8
|
+
result[:en][:date].keys.should eql([:formats])
|
9
|
+
result[:fr][:date].keys.should eql([:formats])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
context "#scoped_translations" do
|
13
|
+
it "filters translations using scope [*.date.formats, *.number.currency.format]" do
|
14
|
+
result = I18n::Js::Translator.scoped_translations(["*.date.formats", "*.number.currency.format"])
|
15
|
+
result[:en].keys.collect(&:to_s).sort.should eql(%w[ date number ])
|
16
|
+
result[:fr].keys.collect(&:to_s).sort.should eql(%w[ date number ])
|
17
|
+
end
|
18
|
+
|
19
|
+
it "filters translations using multi-star scope" do
|
20
|
+
result = I18n::Js::Translator.scoped_translations("*.*.formats")
|
21
|
+
|
22
|
+
result[:en].keys.collect(&:to_s).sort.should eql(%w[ date time ])
|
23
|
+
result[:fr].keys.collect(&:to_s).sort.should eql(%w[ date time ])
|
24
|
+
|
25
|
+
result[:en][:date].keys.should eql([:formats])
|
26
|
+
result[:en][:time].keys.should eql([:formats])
|
27
|
+
|
28
|
+
result[:fr][:date].keys.should eql([:formats])
|
29
|
+
result[:fr][:time].keys.should eql([:formats])
|
30
|
+
end
|
31
|
+
|
32
|
+
it "filters translations using alternated stars" do
|
33
|
+
result = I18n::Js::Translator.scoped_translations("*.admin.*.title")
|
34
|
+
|
35
|
+
result[:en][:admin].keys.collect(&:to_s).sort.should eql(%w[ edit show ])
|
36
|
+
result[:fr][:admin].keys.collect(&:to_s).sort.should eql(%w[ edit show ])
|
37
|
+
|
38
|
+
result[:en][:admin][:show][:title].should eql("Show")
|
39
|
+
result[:fr][:admin][:show][:title].should eql("Visualiser")
|
40
|
+
|
41
|
+
result[:en][:admin][:edit][:title].should eql("Edit")
|
42
|
+
result[:fr][:admin][:edit][:title].should eql("Editer")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%# encoding: utf-8%>
|
2
|
+
|
3
|
+
<% SimplesIdeias::I18n.assert_usable_configuration! %>
|
4
|
+
var I18n = I18n || {};
|
5
|
+
I18n.translations = <%=
|
6
|
+
SimplesIdeias::I18n.translation_segments.each_with_object({}) do |(name, segment),translations|
|
7
|
+
translations.merge!(segment)
|
8
|
+
end.to_json
|
9
|
+
%>;
|