tiny_i18n 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/tiny_i18n.rb ADDED
@@ -0,0 +1,60 @@
1
+ # <libraries>
2
+
3
+ # Yaml
4
+ require "yaml"
5
+
6
+ # TinyI18nVersion
7
+ require "tiny_i18n/tiny_i18n_version"
8
+
9
+ # </libraries>
10
+
11
+ # TinyI18n
12
+ class TinyI18n
13
+
14
+ # TinyI18nVersion
15
+ include TinyI18nVersion
16
+
17
+ # <attributes>
18
+
19
+ # Locale
20
+ attr_accessor :locale
21
+
22
+ # File
23
+ attr_accessor :file
24
+
25
+ # </attributes>
26
+
27
+ # <class methods>
28
+
29
+ # Builder
30
+ def initialize file
31
+ # Default locale
32
+ self.locale ||= :en
33
+ # Load translations
34
+ self.file = YAML.load_file(file)
35
+ end
36
+
37
+ # </class methods>
38
+
39
+ # <instance methods>
40
+
41
+ # Translate
42
+ def translate text, args = {}
43
+ # Translation
44
+ translation = self.file[self.locale]
45
+ # Converting key.subkey into key[subkey] and returning the translation
46
+ translation = text.split(".").map do |key|
47
+ translation = translation[key]
48
+ end.last
49
+ # Variables
50
+ args.each_pair do |key, value|
51
+ # Replace
52
+ translation = translation.to_s.gsub("%{#{key}}", value.to_s)
53
+ end
54
+ # Return
55
+ translation
56
+ end
57
+
58
+ # </instance methods>
59
+
60
+ end
@@ -0,0 +1,17 @@
1
+ # TinyI18nVersion
2
+ module TinyI18nVersion
3
+
4
+ # Version
5
+ module VERSION
6
+ MAJOR = 0
7
+ MINOR = 0
8
+ TINY = 1
9
+
10
+ STRING = [
11
+ MAJOR,
12
+ MINOR,
13
+ TINY
14
+ ].join(".")
15
+ end
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiny_i18n
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Juan Colacelli
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-24 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Reduced version of I18n
22
+ email: juancolacelli@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/tiny_i18n/tiny_i18n_version.rb
31
+ - lib/tiny_i18n.rb
32
+ homepage: https://github.com/juancolacelli/tiny_i18n
33
+ licenses:
34
+ - MIT
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.10
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Reduced version of I18n
65
+ test_files: []
66
+