beawesomeinstead-rubyglot 0.1.0
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/libraries/definitions/countries.rb +1236 -0
- data/libraries/definitions/languages.rb +564 -0
- data/libraries/rubyglot.rb +10 -0
- data/libraries/rubyglot/dictionary.rb +17 -0
- data/libraries/rubyglot/locale.rb +28 -0
- data/rakefile +6 -0
- data/readme +0 -0
- data/rubyglot.gemspec +13 -0
- data/specifications/fixtures/en_US.UTF-8.rb +13 -0
- data/specifications/fixtures/ru_RU.UTF-8.rb +13 -0
- data/specifications/localization/dictionary_spec.rb +4 -0
- data/specifications/localization/locale_spec.rb +33 -0
- data/specifications/spec_helper.rb +2 -0
- metadata +69 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
%w(rubyglot/dictionary rubyglot/locale).map { |x| require x }
|
5
|
+
|
6
|
+
class Object
|
7
|
+
def localize(*args)
|
8
|
+
RubyGlot::Localization::Locale.lookup(*args)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RubyGlot #:nodoc:
|
2
|
+
module Localization #:nodoc:
|
3
|
+
class Dictionary #:nodoc:
|
4
|
+
attr_reader :locale, :entries
|
5
|
+
|
6
|
+
def initialize(locale)
|
7
|
+
@locale, @entries = locale, {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def entry(entry)
|
11
|
+
original = entry[:original]
|
12
|
+
entry.delete_if { |key, value| key == :original }
|
13
|
+
@entries[original] = entry
|
14
|
+
end
|
15
|
+
end # class Dictionary
|
16
|
+
end # module Localization
|
17
|
+
end # module RubyGlot
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RubyGlot #:nodoc:
|
2
|
+
module Localization #:nodoc:
|
3
|
+
class Locale #:nodoc:
|
4
|
+
attr_accessor :language, :country, :encoding
|
5
|
+
|
6
|
+
def initialize(language, country, encoding, options = {})
|
7
|
+
@language, @country, @encoding = language, country, encoding
|
8
|
+
@locale = (language == "English") ? "en_US.UTF-8" : "ru_RU.UTF-8"
|
9
|
+
load "#{options[:storage]}/#{@locale}.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def lookup(string_to_lookup, context = :default, *args)
|
14
|
+
localized = @dictionary.entries[string_to_lookup][context.to_sym][:localized] rescue string_to_lookup
|
15
|
+
sprintf(localized, *args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def define(locale)
|
19
|
+
yield @dictionary = Dictionary.new(locale)
|
20
|
+
end
|
21
|
+
|
22
|
+
def set(language = "English", country = "United States of America", encoding = "UTF-8", options = {})
|
23
|
+
new(language, country, encoding, options)
|
24
|
+
end
|
25
|
+
end # class << self
|
26
|
+
end # class Locale
|
27
|
+
end # module Localization
|
28
|
+
end # module RubyGlot
|
data/rakefile
ADDED
data/readme
ADDED
File without changes
|
data/rubyglot.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "rubyglot"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.date = "2008-07-07"
|
5
|
+
s.summary = "Ruby internationalization."
|
6
|
+
s.email = "beawesomeinstead@yahoo.com"
|
7
|
+
s.homepage = "http://github.com/beawesomeinstead/rubyglot/wikis"
|
8
|
+
s.description = "Simple internationalization solution for Merb/Rails."
|
9
|
+
s.authors = ["beawesomeinstead"]
|
10
|
+
s.has_rdoc = false
|
11
|
+
s.require_paths = ["libraries"]
|
12
|
+
s.files = ["libraries/definitions", "libraries/definitions/countries.rb", "libraries/definitions/languages.rb", "libraries/rubyglot", "libraries/rubyglot/dictionary.rb", "libraries/rubyglot/locale.rb", "libraries/rubyglot.rb", "specifications/fixtures", "specifications/fixtures/en_US.UTF-8.rb", "specifications/fixtures/ru_RU.UTF-8.rb", "specifications/localization", "specifications/localization/dictionary_spec.rb", "specifications/localization/locale_spec.rb", "specifications/spec_helper.rb", "rakefile", "readme", "rubyglot.gemspec"]
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class RubyGlot::Localization::Locale
|
2
|
+
define "en_US.UTF-8" do |dictionary|
|
3
|
+
dictionary.entry(
|
4
|
+
:original => "lolcatz",
|
5
|
+
:default => { :localized => "lolcatz localized", :state => "active" },
|
6
|
+
:dogs => { :localized => "loldogs", :state => "active" }
|
7
|
+
)
|
8
|
+
dictionary.entry(
|
9
|
+
:original => "lol %03d dogs",
|
10
|
+
:dogs => { :localized => "lol %03d dogs", :state => "active" }
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class RubyGlot::Localization::Locale
|
2
|
+
define "ru_RU.UTF-8" do |dictionary|
|
3
|
+
dictionary.entry(
|
4
|
+
:original => "lolcatz",
|
5
|
+
:default => { :localized => "смешные котята", :state => "active" },
|
6
|
+
:dogs => { :localized => "смешные собачки", :state => "active" }
|
7
|
+
)
|
8
|
+
dictionary.entry(
|
9
|
+
:original => "lol %03d dogs",
|
10
|
+
:dogs => { :localized => "лол %04d собачек", :state => "active" }
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
|
2
|
+
|
3
|
+
describe RubyGlot::Localization::Locale do
|
4
|
+
it "should translate strings (Original/English)" do
|
5
|
+
RubyGlot::Localization::Locale.set("English", "United States of America", "UTF-8", { :storage => "specifications/fixtures" })
|
6
|
+
localize("lolcatz").should == "lolcatz localized"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should translate strings (Original/Russian)" do
|
10
|
+
RubyGlot::Localization::Locale.set("Russian", "Russian Federation", "UTF-8", { :storage => "specifications/fixtures" })
|
11
|
+
localize("lolcatz").should == "смешные котята"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should translate strings with namespace (Original/English)" do
|
15
|
+
RubyGlot::Localization::Locale.set("English", "United States of America", "UTF-8", { :storage => "specifications/fixtures" })
|
16
|
+
localize("lolcatz", "dogs").should == "loldogs"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should translate strings with namespace (Original/Russian)" do
|
20
|
+
RubyGlot::Localization::Locale.set("Russian", "Russian Federation", "UTF-8", { :storage => "specifications/fixtures" })
|
21
|
+
localize("lolcatz", "dogs").should == "смешные собачки"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should translate strings with number formatting (Original/English)" do
|
25
|
+
RubyGlot::Localization::Locale.set("English", "United States of America", "UTF-8", { :storage => "specifications/fixtures" })
|
26
|
+
localize("lol %03d dogs", "dogs", 16).should == "lol 016 dogs"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should translate strings with number formatting (Original/Russian)" do
|
30
|
+
RubyGlot::Localization::Locale.set("Russian", "Russian Federation", "UTF-8", { :storage => "specifications/fixtures" })
|
31
|
+
localize("lol %03d dogs", "dogs", 16).should == "лол 0016 собачек"
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: beawesomeinstead-rubyglot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- beawesomeinstead
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-07-07 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Simple internationalization solution for Merb/Rails.
|
17
|
+
email: beawesomeinstead@yahoo.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- libraries/definitions
|
26
|
+
- libraries/definitions/countries.rb
|
27
|
+
- libraries/definitions/languages.rb
|
28
|
+
- libraries/rubyglot
|
29
|
+
- libraries/rubyglot/dictionary.rb
|
30
|
+
- libraries/rubyglot/locale.rb
|
31
|
+
- libraries/rubyglot.rb
|
32
|
+
- specifications/fixtures
|
33
|
+
- specifications/fixtures/en_US.UTF-8.rb
|
34
|
+
- specifications/fixtures/ru_RU.UTF-8.rb
|
35
|
+
- specifications/localization
|
36
|
+
- specifications/localization/dictionary_spec.rb
|
37
|
+
- specifications/localization/locale_spec.rb
|
38
|
+
- specifications/spec_helper.rb
|
39
|
+
- rakefile
|
40
|
+
- readme
|
41
|
+
- rubyglot.gemspec
|
42
|
+
has_rdoc: false
|
43
|
+
homepage: http://github.com/beawesomeinstead/rubyglot/wikis
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- libraries
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.2.0
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: Ruby internationalization.
|
68
|
+
test_files: []
|
69
|
+
|