cell-i18n 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gems.test +2 -0
- data/LICENSE +21 -0
- data/Makefile +4 -0
- data/README.md +0 -0
- data/cell-i18n.gemspec +17 -0
- data/lib/cell_i18n.rb +34 -0
- data/test/cell_i18n.rb +84 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0b3894bf210aa2fb241535500c184c4c76eca7b7
|
4
|
+
data.tar.gz: c95e0bfabdc91e14c94ee325dde6d4f0caa39a2b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a6ec8ddcac73cdbbbf3e48116b771baca251ba1851769cade9b5645c60bcf35d6fc53776b6e9cce184ab53ebe7683fc05ca0bb87f1c2dbe02b478604f8452ee
|
7
|
+
data.tar.gz: ce36ee002a3ba03e6834e7e63a6410636693b04d4e2e255cd4cae7c5ff79deed40ecdc383cb2d12c3e04eef3e36476a76de41043604c416d293afd3b285a89e1
|
data/.gems.test
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Lucas Tolchinsky
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/Makefile
ADDED
data/README.md
ADDED
File without changes
|
data/cell-i18n.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "cell-i18n"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.summary = "i18n library inspired in Trailblazer's Cell"
|
5
|
+
s.description = s.summary
|
6
|
+
s.authors = ["Lucas Tolchinsky"]
|
7
|
+
s.email = ["tonchis@protonmail.com"]
|
8
|
+
s.homepage = "https://gitlab.com/tonchis/cell-i18n"
|
9
|
+
s.license = "MIT"
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
|
13
|
+
s.add_development_dependency "dep", ">= 1.1.0"
|
14
|
+
s.add_development_dependency "cutest", ">= 1.2.3"
|
15
|
+
s.add_development_dependency "mocoso", ">= 1.2.3"
|
16
|
+
end
|
17
|
+
|
data/lib/cell_i18n.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module CellI18n
|
4
|
+
def i18n(key, locale = i18n_locale)
|
5
|
+
translation_path = namespace + [key]
|
6
|
+
dictionaries[locale].dig(*translation_path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def i18n_file_path
|
10
|
+
"lib/locale".freeze
|
11
|
+
end
|
12
|
+
|
13
|
+
def i18n_locale
|
14
|
+
"en".freeze
|
15
|
+
end
|
16
|
+
|
17
|
+
def i18n_parser
|
18
|
+
[JSON.method(:parse), "json".freeze]
|
19
|
+
end
|
20
|
+
|
21
|
+
private def namespace
|
22
|
+
self.class.name.split("::".freeze)
|
23
|
+
end
|
24
|
+
|
25
|
+
private def dictionaries
|
26
|
+
@@dictionaries ||= begin
|
27
|
+
hash = Hash.new do |hash, locale|
|
28
|
+
parser, extension = i18n_parser
|
29
|
+
dictionary = parser.(File.read(File.join(i18n_file_path, "#{locale}.#{extension}")))
|
30
|
+
hash[locale] = dictionary
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/test/cell_i18n.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require "cutest"
|
2
|
+
require "mocoso"
|
3
|
+
require_relative "../lib/cell_i18n"
|
4
|
+
|
5
|
+
include Mocoso
|
6
|
+
|
7
|
+
module Page
|
8
|
+
# Let's pretend these are `Trailblazer::Cell`s
|
9
|
+
class Header
|
10
|
+
include CellI18n
|
11
|
+
|
12
|
+
def self.call
|
13
|
+
new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Body
|
18
|
+
include CellI18n
|
19
|
+
|
20
|
+
def self.call
|
21
|
+
new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
scope "namespace" do
|
27
|
+
test "honours the namespace of the class" do
|
28
|
+
assert_equal ["Page", "Header"], Page::Header.().send(:namespace)
|
29
|
+
assert_equal ["Page", "Body"], Page::Body.().send(:namespace)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
scope "translation lookup" do
|
34
|
+
test "the default file path is lib/locale" do
|
35
|
+
assert_equal "lib/locale", Page::Header.().i18n_file_path
|
36
|
+
end
|
37
|
+
|
38
|
+
test "the default locale is en" do
|
39
|
+
assert_equal "en", Page::Header.().i18n_locale
|
40
|
+
end
|
41
|
+
|
42
|
+
test "the default parser is JSON" do
|
43
|
+
parser, extension = Page::Header.().i18n_parser
|
44
|
+
|
45
|
+
assert_equal JSON.method(:parse), parser
|
46
|
+
assert_equal "json", extension
|
47
|
+
end
|
48
|
+
|
49
|
+
test "searches for translations lib/locale/*.json files" do
|
50
|
+
file = <<-EOF
|
51
|
+
{
|
52
|
+
"Page": {
|
53
|
+
"Header": {
|
54
|
+
"foo": "foo in english"
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
EOF
|
59
|
+
|
60
|
+
expect(File, :read, with: ["lib/locale/en.json"], return: file) do
|
61
|
+
assert_equal "foo in english", Page::Header.().i18n("foo")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
test "can use YAML as well" do
|
66
|
+
file = <<-EOF
|
67
|
+
Page:
|
68
|
+
Header:
|
69
|
+
foo: "foo in english"
|
70
|
+
EOF
|
71
|
+
|
72
|
+
expect(File, :read, with: ["lib/locale/en.yml"], return: file) do
|
73
|
+
class Page::Header
|
74
|
+
require "yaml"
|
75
|
+
|
76
|
+
def i18n_parser
|
77
|
+
[YAML.method(:load), "yml"]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
assert_equal "foo in english", Page::Header.().i18n("foo")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cell-i18n
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Tolchinsky
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dep
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cutest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mocoso
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.2.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.3
|
55
|
+
description: i18n library inspired in Trailblazer's Cell
|
56
|
+
email:
|
57
|
+
- tonchis@protonmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gems.test"
|
63
|
+
- LICENSE
|
64
|
+
- Makefile
|
65
|
+
- README.md
|
66
|
+
- cell-i18n.gemspec
|
67
|
+
- lib/cell_i18n.rb
|
68
|
+
- test/cell_i18n.rb
|
69
|
+
homepage: https://gitlab.com/tonchis/cell-i18n
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.5.1
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: i18n library inspired in Trailblazer's Cell
|
93
|
+
test_files: []
|
94
|
+
has_rdoc:
|