localite 0.3 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/Manifest +44 -0
  2. data/VERSION +1 -1
  3. data/bin/list-tr +10 -0
  4. data/lib/localite.rb +161 -43
  5. data/lib/localite/filter.rb +23 -64
  6. data/lib/localite/format.rb +36 -0
  7. data/lib/localite/node_filter.rb +197 -0
  8. data/lib/localite/scopes.rb +93 -0
  9. data/lib/localite/settings.rb +139 -17
  10. data/lib/localite/storage.rb +132 -0
  11. data/lib/localite/template.rb +29 -25
  12. data/lib/localite/tr.rb +292 -0
  13. data/lib/localite/translate.rb +46 -20
  14. data/localite.gemspec +9 -6
  15. data/localite.tmproj +3 -99
  16. data/tasks/echoe.rake +1 -1
  17. data/test/i18n/de.tr +5 -0
  18. data/test/i18n/en.tr +16 -0
  19. data/test/rails/Rakefile +10 -0
  20. data/test/rails/app/controllers/application_controller.rb +10 -0
  21. data/test/rails/app/controllers/localite_controller.rb +20 -0
  22. data/test/rails/app/views/localite/index.html.erb +19 -0
  23. data/test/rails/app/views/localite/template.de.html.erb +1 -0
  24. data/test/rails/app/views/localite/template.en.html.erb +1 -0
  25. data/test/rails/config/boot.rb +110 -0
  26. data/test/rails/config/environment.rb +50 -0
  27. data/test/rails/config/environments/development.rb +17 -0
  28. data/test/rails/config/environments/production.rb +28 -0
  29. data/test/rails/config/environments/test.rb +28 -0
  30. data/test/rails/config/initializers/new_rails_defaults.rb +21 -0
  31. data/test/rails/config/initializers/session_store.rb +15 -0
  32. data/test/rails/config/locales/de.yml +4 -0
  33. data/test/rails/config/locales/en.yml +4 -0
  34. data/test/rails/config/routes.rb +13 -0
  35. data/test/rails/script/console +3 -0
  36. data/test/rails/script/server +3 -0
  37. data/test/rails/test/functional/localite_controller_test.rb +56 -0
  38. data/test/rails/test/test_helper.rb +38 -0
  39. data/test/test.rb +4 -1
  40. metadata +51 -11
  41. data/lib/localite/scope.rb +0 -140
  42. data/test/i18n/de.yml +0 -15
@@ -1,140 +0,0 @@
1
- module Localite::Scope
2
- #
3
- # scope allows to set a scope around a translation. A scoped translation
4
- #
5
- # Localite.scope("scope") do
6
- # "msg".t
7
- # end
8
- #
9
- # will look up "scope.msg" and "msg", in that order, and return the first
10
- # matching translation in the current locale. Scopes can be stacked; looking
11
- # up a scoped translation
12
- # Localite.scope("outer") do
13
- # Localite.scope("scope") do
14
- # "msg".t
15
- # end
16
- # end
17
- #
18
- # will look up "outer.scope.msg", "scope.msg", "msg".
19
- #
20
- # If no translation will be found we look up the same entries in the base
21
- # locale.
22
- def scope(*args, &block)
23
- return yield if args.empty?
24
-
25
- scopes.exec(args.shift) do
26
- scope *args, &block
27
- end
28
- end
29
-
30
- def scopes
31
- Thread.current[:"localite:scopes"] ||= Scopes.new
32
- end
33
-
34
- #
35
- # The mode setting defines how the template engine deals with its
36
- # parameters. In :html mode all parameters will be subject to HTML
37
- # escaping, while in :text mode the parameters remain unchanged.
38
- def html(&block)
39
- in_mode :html, &block
40
- end
41
-
42
- def text(&block)
43
- in_mode :text, &block
44
- end
45
-
46
- def mode
47
- Thread.current[:"localite:mode"] || :text
48
- end
49
-
50
- private
51
-
52
- def in_mode(mode, &block)
53
- old = Thread.current[:"localite:mode"]
54
- Thread.current[:"localite:mode"] = mode
55
- yield
56
- ensure
57
- Thread.current[:"localite:mode"] = old
58
- end
59
-
60
-
61
- class Scopes < Array
62
- def exec(s, &block)
63
- s = "#{last}.#{s}" if last
64
- push s
65
-
66
- yield
67
- ensure
68
- pop
69
- end
70
-
71
- def each(s)
72
- reverse_each do |entry|
73
- yield "#{entry}.#{s}"
74
- end
75
-
76
- yield s
77
- end
78
-
79
- def first(s)
80
- each(s) do |entry|
81
- return entry
82
- end
83
- end
84
- end
85
- end
86
-
87
- module Localite::Scope::Etest
88
- Scopes = Localite::Scope::Scopes
89
-
90
- def test_scope
91
- scope = Scopes.new
92
- scope.exec("a") do
93
- scope.exec("b") do
94
- scope.exec("b") do
95
- r = []
96
- scope.each("str") do |scoped|
97
- r << scoped
98
- end
99
- assert_equal %w(a.b.b.str a.b.str a.str str), r
100
- end
101
- end
102
- end
103
- end
104
-
105
- def test_more_scopes
106
- Localite.scope("a", :b, "b") do
107
- r = []
108
- Localite.scopes.each("str") do |scoped|
109
- r << scoped
110
- end
111
- assert_equal %w(a.b.b.str a.b.str a.str str), r
112
- end
113
- end
114
-
115
- def test_more_scopes_w_dots
116
- Localite.scope("a", :b, "b.c.d") do
117
- r = []
118
- Localite.scopes.each("str.y") do |scoped|
119
- r << scoped
120
- end
121
- assert_equal %w(a.b.b.c.d.str.y a.b.str.y a.str.y str.y), r
122
- end
123
- end
124
-
125
- def test_empty_scopes
126
- r = []
127
- Localite.scopes.each("str.y") do |scoped|
128
- r << scoped
129
- end
130
- assert_equal %w(str.y), r
131
- end
132
-
133
- def test_modi
134
- assert_equal "abc", "param".t(:xxx => "abc")
135
- assert_equal "a > c", "param".t(:xxx => "a > c")
136
- assert_equal "a > c", Localite.text { "param".t(:xxx => "a > c") }
137
- assert_equal "a &gt; c", Localite.html { "param".t(:xxx => "a > c") }
138
- assert_equal "a > c", "param".t(:xxx => "a > c")
139
- end
140
- end
@@ -1,15 +0,0 @@
1
- #
2
- # Some translation "fixtures"
3
- de:
4
- t: "de.t"
5
- outer:
6
- inner:
7
- x1: "de/outer/inner/x1"
8
-
9
- en:
10
- param: "{* xxx *}"
11
- base: "en_only"
12
- t: "en.t"
13
- outer:
14
- inner:
15
- x1: "en/outer/inner/x1"