-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* genki: Updated localization of time and date Added some specs and support for localization of times and dates. Added a spec for domain specific translation. Added more specs to locale detector. Added specs for locale detection Implemented hierarchical localization. Removed core_ext and cleaned up entirely Return key if any localizations are not found Renamed country guesser to locale detector. Updated version to force github gererated gems. Fixed bug. Don't lookup ymls in Merb.root Changed hash to mash Added CountryGuesser. Updated Rakefile and incremented version number. Conflicts: lib/merb_babel/m_locale.rb
- Loading branch information
Showing
15 changed files
with
416 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.DS_Store | ||
*/.DS_Store | ||
*/.DS_Store | ||
pkg | ||
log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,58 @@ | ||
require 'rubygems' | ||
require 'rake/gempackagetask' | ||
require 'rubygems/specification' | ||
require 'date' | ||
require "spec/rake/spectask" | ||
|
||
PLUGIN = "merb_babel" | ||
NAME = "merb_babel" | ||
GEM_VERSION = "0.1.0" | ||
require 'merb-core' | ||
require 'merb-core/tasks/merb' | ||
|
||
GEM_NAME = "merb_babel" | ||
GEM_VERSION = "0.1.1.2" | ||
AUTHOR = "Matt Aimonetti" | ||
EMAIL = "mattaimonetti@gmail.com" | ||
HOMEPAGE = "http://github.com/mattetti/merb_babel/" | ||
SUMMARY = "Merb plugin that provides simple localization/internationalisation" | ||
|
||
spec = Gem::Specification.new do |s| | ||
s.name = NAME | ||
s.rubyforge_project = 'merb' | ||
s.name = GEM_NAME | ||
s.version = GEM_VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.has_rdoc = true | ||
s.extra_rdoc_files = ["README", "LICENSE", 'TODO'] | ||
s.extra_rdoc_files = ["README.markdown", "LICENSE", 'TODO'] | ||
s.summary = SUMMARY | ||
s.description = s.summary | ||
s.author = AUTHOR | ||
s.email = EMAIL | ||
s.homepage = HOMEPAGE | ||
s.add_dependency('merb-core', '~> 1.0.0') | ||
s.add_dependency('merb', '>= 1.0') | ||
s.add_dependency('locale', '>= 0.9.0') | ||
s.require_path = 'lib' | ||
s.autorequire = PLUGIN | ||
s.files = %w(LICENSE README.markdown Rakefile TODO) + Dir.glob("{lib,spec}/**/*") | ||
end | ||
|
||
Rake::GemPackageTask.new(spec) do |pkg| | ||
pkg.gem_spec = spec | ||
end | ||
|
||
desc "install the plugin locally" | ||
task :install => [:package] do | ||
sh %{sudo gem install pkg/#{NAME}-#{GEM_VERSION} --no-update-sources} | ||
desc "install the plugin as a gem" | ||
task :install do | ||
Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION) | ||
end | ||
|
||
desc "Uninstall the gem" | ||
task :uninstall do | ||
Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION) | ||
end | ||
|
||
desc "create a gemspec file" | ||
task :make_spec do | ||
File.open("#{GEM}.gemspec", "w") do |file| | ||
desc "Create a gemspec file" | ||
task :gemspec do | ||
File.open("#{GEM_NAME}.gemspec", "w") do |file| | ||
file.puts spec.to_ruby | ||
end | ||
end | ||
|
||
namespace :jruby do | ||
|
||
desc "Run :package and install the resulting .gem with jruby" | ||
task :install => :package do | ||
sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri} | ||
end | ||
|
||
desc "Run specs" | ||
task :spec do | ||
sh "spec --color spec" | ||
end | ||
|
||
desc "Run the specs" | ||
Spec::Rake::SpecTask.new("specs") do |t| | ||
t.spec_opts = ["--format", "specdoc", "--colour"] | ||
t.spec_files = Dir["spec/**/*_spec.rb"].sort | ||
end | ||
task :default => :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module LocaleDetector | ||
LANGUAGE_TO_COUNTRY = { | ||
"nn"=>["NO"], | ||
"uk"=>["UA"], | ||
"it"=>["IT", "GI", "CH", "LY", "SM"], | ||
"zh_TW"=>["TT", "VN", "HK"], | ||
"no"=>["NO"], | ||
"st"=>["ZA"], | ||
"tk"=>["TM"], | ||
"bn"=>["IN"], | ||
"mn"=>["MN"], | ||
"ja"=>["JP"], | ||
"fr"=>["FR", "CD", "GG", "RW", "CG", "LU", "TT", "CH", "CI", "JE", "SC", | ||
"VN", "BE", "MU", "DJ", "BI", "CA"], | ||
"hi"=>["TT", "AE", "IN"], | ||
"de"=>["DE", "LU", "CH", "LI", "AT", "BE", "RO"], | ||
"ne"=>["NP"], "jw"=>["ID"], | ||
"ta"=>["IN", "SG"], | ||
"tl"=>["PH"], | ||
"pt_PT"=>["PT", "GI"], | ||
"hu"=>["HU", "SK", "RO"], | ||
"sk"=>["SK"], | ||
"fi"=>["FI"], | ||
"sv"=>["SE", "FI"], | ||
"iw"=>["IL"], | ||
"az"=>["AZ"], | ||
"zh"=>["TW"], | ||
"ru"=>["RU", "KZ", "KG", "AZ", "LV", "UA", "TM", "AM", "UZ"], | ||
"ky"=>["KG"], | ||
"es"=>["ES", "HN", "CU", "PR", "TT", "PA", "VE", "DO", "BO", "GI", "PE", | ||
"PY", "NI", "CL", "SV", "CO", "UY", "BZ", "CR", "EC", "GT", "AR", "MX"], | ||
"ko"=>["KR"], | ||
"pt_BR"=>["BR"], | ||
"sw"=>["RW", "KE"], | ||
"ga"=>["IE"], | ||
"id"=>["ID"], | ||
"eu"=>["ES"], | ||
"gl"=>["ES"], | ||
"xh"=>["ZA"], | ||
"uz"=>["TM", "UZ"], | ||
"mr"=>["IN"], | ||
"fa"=>["AE"], | ||
"zu"=>["LS", "ZA"], | ||
"af"=>["NA", "ZA"], | ||
"pl"=>["PL"], | ||
"hy"=>["AM"], | ||
"pa"=>["PK"], | ||
"te"=>["IN"], | ||
"ar"=>["AE", "LY", "SA", "DJ"], | ||
"ms"=>["MY", "SG"], | ||
"el"=>["GR"], | ||
"ro"=>["RO"], | ||
"mt"=>["MT"], | ||
"ur"=>["AE", "PK"], | ||
"da"=>["DK", "GL"], | ||
"ca"=>["ES"], | ||
"tr"=>["TR"], | ||
"zh_CN"=>["SG"], | ||
"nl"=>["NL", "BE", "ID"], | ||
"vi"=>["VN"], | ||
"lt"=>["LT", "LV"], | ||
"th"=>["TH"], | ||
"fo"=>["DK"], | ||
"en"=>["US", "AS", "IE", "NP", "MY", "UK", "FM", "VC", "PR", "TT", "AU", | ||
"PA", "NA", "GG", "LS", "RW", "VG", "AE", "GI", "VI", "AG", "TH", "CH", | ||
"NF", "JE", "AI", "GL", "PH", "CK", "GM", "LY", "IN", "NZ", "NI", "SC", | ||
"PK", "VN", "MS", "TO", "MT", "BE", "PN", "MU", "UG", "SG", "ZA", "BZ", | ||
"SH", "MW", "FJ", "CR", "HK", "JM", "KE", "CA", "ID"], | ||
"lv"=>["LV"] | ||
}.freeze | ||
|
||
module_function | ||
def countries_from_language(language) | ||
LANGUAGE_TO_COUNTRY[language] | ||
end | ||
|
||
def country_from_language(language) | ||
(countries_from_language(language) || []).first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
module MI18n | ||
|
||
def self.lookup(options) | ||
key = options[:key] | ||
keys = [options[:keys].map{|key| key.to_s}].flatten | ||
language = options[:language] | ||
country = options[:country] | ||
|
||
raise ArgumentError, "You need to pass a language reference" unless language | ||
raise ArgumentError, "You need to pass a localization key" unless key | ||
raise ArgumentError, "language: #{language} not found" unless ML10n.localizations[language] | ||
raise ArgumentError, "You need to pass a localization key" if keys.empty? | ||
raise ArgumentError, | ||
"language: #{language} not found" unless ML10n.localizations[language] | ||
|
||
full_location = nil | ||
full_location = lookup_with_full_locale(key, language, country) if country | ||
full_location = lookup_with_full_locale(keys, language, country) if country | ||
|
||
if full_location | ||
return full_location | ||
else | ||
return ML10n.localizations[language][key] | ||
return lookup_with_language(keys, language) || keys.last | ||
end | ||
end | ||
|
||
def self.lookup_with_language(keys, language) | ||
lookup_with_hash(keys, ML10n.localizations[language]) | ||
end | ||
|
||
def self.lookup_with_full_locale(key, language, country) | ||
def self.lookup_with_full_locale(keys, language, country) | ||
if ML10n.localizations.has_key?(language) | ||
ML10n.localizations[language].has_key?(country) ? ML10n.localizations[language][country][key] : nil | ||
ML10n.localizations[language].has_key?(country) ? | ||
lookup_with_hash(keys, ML10n.localizations[language][country]) : nil | ||
else | ||
nil | ||
end | ||
end | ||
|
||
end | ||
def self.lookup_with_hash(keys, l_hash) | ||
keys.inject(l_hash){|h,k| h[k] rescue nil} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
ecbf11e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you ;-)