mack-localization 0.8.0.101 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mack-localization.rb +8 -0
- data/lib/mack-localization/configuration.rb +42 -15
- data/lib/mack-localization/translator.rb +17 -7
- metadata +3 -3
data/lib/mack-localization.rb
CHANGED
@@ -68,3 +68,11 @@ dir_globs = Dir.glob(File.join(File.dirname(__FILE__), "mack-localization", "**/
|
|
68
68
|
dir_globs.each do |d|
|
69
69
|
require d
|
70
70
|
end
|
71
|
+
|
72
|
+
|
73
|
+
configatron.mack.localization.set_default(:base_language, 'en')
|
74
|
+
configatron.mack.localization.set_default(:supported_languages, %w{bp en fr it de es})
|
75
|
+
configatron.mack.localization.set_default(:char_encoding, 'us-ascii')
|
76
|
+
configatron.mack.localization.set_default(:dynamic_translation, false)
|
77
|
+
configatron.mack.localization.set_default(:base_directory, [Mack::Paths.app('lang')])
|
78
|
+
configatron.mack.localization.set_default(:content_expiry, 3600)
|
@@ -5,22 +5,49 @@
|
|
5
5
|
# {config_dir}/localization/ inside the application directory.
|
6
6
|
# If the file doesn't exist then it will just load default configuration.
|
7
7
|
#
|
8
|
-
module Mack
|
9
|
-
module Localization # :nodoc:
|
10
|
-
module Configuration
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
module Mack
|
10
|
+
module Localization
|
11
|
+
|
12
|
+
class Configuration
|
13
|
+
include Singleton
|
14
|
+
def initialize
|
15
|
+
@storage = Mack::Localization::Storage.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup
|
19
|
+
yield @storage
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(sym, *args)
|
23
|
+
@storage.send(sym, *args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Storage
|
28
|
+
|
29
|
+
def base_directory= (path)
|
30
|
+
arr = configatron.mack.localization.base_directory
|
31
|
+
arr = [] if arr.is_a?(Configatron::Store) and !arr.is_a?(Array)
|
32
|
+
arr << path
|
33
|
+
arr.uniq!
|
34
|
+
configatron.mack.localization.base_directory = arr
|
35
|
+
end
|
18
36
|
|
19
|
-
|
20
|
-
|
21
|
-
|
37
|
+
def base_directory
|
38
|
+
arr = configatron.mack.localization.base_directory
|
39
|
+
arr = [Mack::Paths.app('lang')] if arr.is_a?(Configatron::Store) and !arr.is_a?(Array)
|
40
|
+
return (arr.size == 1) ? arr[0] : arr
|
22
41
|
end
|
23
|
-
|
42
|
+
|
43
|
+
def method_missing(sym, *args)
|
44
|
+
supported_settings = [:base_language, :supported_languages, :char_encoding, :dynamic_translation, :content_expiry,
|
45
|
+
:base_language=, :supported_languages=, :char_encoding=, :dynamic_translation=, :content_expiry=]
|
46
|
+
if supported_settings.include?(sym)
|
47
|
+
configatron.mack.localization.send(sym, *args)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
24
51
|
end
|
25
52
|
end
|
26
53
|
|
@@ -30,6 +57,6 @@ class Object
|
|
30
57
|
# Give access to the mack l10n config object from anywhere inside the application
|
31
58
|
#
|
32
59
|
def l10n_config
|
33
|
-
|
60
|
+
Mack::Localization::Configuration.instance
|
34
61
|
end
|
35
|
-
end
|
62
|
+
end
|
@@ -31,7 +31,7 @@ module Mack
|
|
31
31
|
raise Mack::Localization::Errors::UnsupportedLanguage.new(base_lang) if !l10n_config.supported_languages.include?(base_lang)
|
32
32
|
|
33
33
|
cache_key = "#{view_sym}_#{base_lang}_content"
|
34
|
-
path = File.join(
|
34
|
+
path = File.join("views", "#{view_name}", "content_#{base_lang}.yml")
|
35
35
|
content_hash = load_content_hash(cache_key, base_lang, path)
|
36
36
|
|
37
37
|
raise Mack::Localization::Errors::UnknownStringKey.new(key) if content_hash[key] == nil
|
@@ -60,7 +60,7 @@ module Mack
|
|
60
60
|
raise Mack::Localization::Errors::UnsupportedLanguage.new(base_lang) if !l10n_config.supported_languages.include?(base_lang)
|
61
61
|
|
62
62
|
cache_key = "rules_content_#{base_lang}"
|
63
|
-
path = File.join(
|
63
|
+
path = File.join("rules", "inflection_#{base_lang}.yml")
|
64
64
|
content_hash = load_content_hash(cache_key, base_lang, path)
|
65
65
|
|
66
66
|
hash = content_hash[type]
|
@@ -81,17 +81,27 @@ module Mack
|
|
81
81
|
|
82
82
|
private
|
83
83
|
|
84
|
-
def load_content_hash(cache_key, base_lang,
|
84
|
+
def load_content_hash(cache_key, base_lang, rsc_path)
|
85
85
|
# content_hash = l10n_config.send("#{cache_key}")
|
86
86
|
content_hash = l10n_cache.get("#{cache_key}")
|
87
87
|
|
88
88
|
if content_hash.nil?
|
89
89
|
raise Mack::Localization::Errors::InvalidConfiguration.new if base_lang.nil?
|
90
|
-
raise Mack::Localization::Errors::LanguageFileNotFound.new(path) if !File.exists?(path)
|
91
90
|
|
92
|
-
|
93
|
-
|
94
|
-
|
91
|
+
base_dir_arr = [l10n_config.base_directory].flatten
|
92
|
+
found_path = false
|
93
|
+
base_dir_arr.each do |base_dir|
|
94
|
+
path = File.join(base_dir, rsc_path)
|
95
|
+
found_path = File.exists?(path)
|
96
|
+
if found_path
|
97
|
+
data = File.read(path)
|
98
|
+
content_hash = YAML.load(data)
|
99
|
+
l10n_cache.set("#{cache_key}", content_hash, l10n_config.content_expiry)
|
100
|
+
break
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
raise Mack::Localization::Errors::LanguageFileNotFound.new(rsc_path) if !found_path
|
95
105
|
end
|
96
106
|
|
97
107
|
return content_hash
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mack-localization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darsono Sutedja
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-10-
|
12
|
+
date: 2008-10-26 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.8.
|
33
|
+
version: 0.8.1
|
34
34
|
version:
|
35
35
|
description: Localization support for Mack Framework
|
36
36
|
email: Darsono.Sutedja@gmail.com
|