cldr-languages 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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +8 -0
- data/LICENSE +20 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/cldr-languages.gemspec +23 -0
- data/lib/cldr/languages/version.rb +5 -0
- data/lib/languages.rb +75 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c3485b0983471f017b68ee1e51793f21109dcbaf
|
4
|
+
data.tar.gz: 23789b3323dc9a30655f1445e85c6b111ac99146
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: db10f060fdae3f3c318813b824042996e6f2da1e92d00a2768292507260ee05ddb982db49d16d25946a127da62889a97eda703d9769925f03b1ae55fe61ae29d
|
7
|
+
data.tar.gz: e865eed017e8cecaa83efda7537416e94faabcda97f20f2aa87fe1f8390afdefe0c38e24fc916b82202e041f8e0912729136964c1af95dce8bbe6bd8317d742d
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
projectFilesBackup
|
15
|
+
config/locales/languages.*.yml
|
16
|
+
.idea
|
17
|
+
Gemfile.lock
|
18
|
+
|
19
|
+
# YARD artifacts
|
20
|
+
.yardoc
|
21
|
+
_yardoc
|
22
|
+
doc/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Florian Schäffler
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
cdlr-languages
|
2
|
+
==============
|
3
|
+
Installation
|
4
|
+
------------
|
5
|
+
gem install cldr-languages
|
6
|
+
|
7
|
+
Usage
|
8
|
+
-----
|
9
|
+
require 'cldr'
|
10
|
+
require 'languages'
|
11
|
+
include Cldr
|
12
|
+
include Languages
|
13
|
+
|
14
|
+
# imports all available languages to the folder config/locales
|
15
|
+
import
|
16
|
+
|
17
|
+
# retrieves a list of available language codes
|
18
|
+
language_codes
|
19
|
+
|
20
|
+
# retrieves a hash of available language codes and language names in English
|
21
|
+
localized_languages
|
22
|
+
|
23
|
+
# retrieves a hash of available language codes and language name in German with fallback English
|
24
|
+
localized_languages(language: 'de')
|
25
|
+
|
26
|
+
# retrieves a hash of available language codes and language name in German with fallback French
|
27
|
+
localized_languages(language: 'de', :fallback 'fr')
|
28
|
+
|
29
|
+
# retrieves a hash of available language codes and language name localized to the language code with fallback English
|
30
|
+
localized_languages(language: 'zxx')
|
31
|
+
|
32
|
+
# retrieves a hash of available language codes and language name localized to the language code with fallback German
|
33
|
+
localized_languages(language: 'zxx', fallback: 'de')
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cldr/languages/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cldr-languages"
|
8
|
+
spec.version = Cldr::Languages::VERSION
|
9
|
+
spec.authors = ["Florian Schäffler"]
|
10
|
+
spec.email = ["ruby@schf.de"]
|
11
|
+
spec.summary = %q{Localization of languages to a given language or its own language}
|
12
|
+
spec.description = %q{Use language code 'zzx' for getting languages in its own language}
|
13
|
+
spec.homepage = "http://www.schf.de"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake", "~> 0"
|
23
|
+
end
|
data/lib/languages.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'cldr/languages/version'
|
2
|
+
require 'cldr'
|
3
|
+
require 'yaml'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module Cldr
|
7
|
+
module Languages
|
8
|
+
|
9
|
+
DEFAULT_LANGUAGE_CODE = 'en'
|
10
|
+
DEFAULT_SELF_LOCALIZATION_CODE = 'zxx'
|
11
|
+
|
12
|
+
def import
|
13
|
+
languageCodes = language_codes(true)
|
14
|
+
|
15
|
+
if !File.directory?('config')
|
16
|
+
FileUtils.mkdir_p('config')
|
17
|
+
FileUtils.mkdir_p('config/locales')
|
18
|
+
elsif !File.directory?('config/locales')
|
19
|
+
FileUtils.mkdir_p('config/locales')
|
20
|
+
end
|
21
|
+
|
22
|
+
languageCodes.each do |languageCode|
|
23
|
+
localizedLanguages = localized_languages(language: languageCode)
|
24
|
+
localizedLanguagesContent = Hash.new
|
25
|
+
localizedLanguagesContent[languageCode] = localizedLanguages
|
26
|
+
yamlContent = localizedLanguagesContent.to_yaml
|
27
|
+
|
28
|
+
File.open("config/locales/languages.#{languageCode}.yml", 'w') do |f|
|
29
|
+
f.write(yamlContent)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def language_codes(includeSelfLocalization = false)
|
35
|
+
defaultLanguage = language(DEFAULT_LANGUAGE_CODE)
|
36
|
+
defaultLanguageObject = CLDR::Object.new(locale: defaultLanguage)
|
37
|
+
|
38
|
+
languageCodes = defaultLanguageObject.core.languages.keys
|
39
|
+
|
40
|
+
if includeSelfLocalization then
|
41
|
+
return languageCodes
|
42
|
+
else
|
43
|
+
return languageCodes.reject! { |k| k == DEFAULT_SELF_LOCALIZATION_CODE }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def localized_languages(opts = {})
|
48
|
+
localizationLanguage = language(opts[:language])
|
49
|
+
fallbackLanguage = language(opts[:fallback])
|
50
|
+
|
51
|
+
if opts[:language] && opts[:language].to_s == DEFAULT_SELF_LOCALIZATION_CODE then
|
52
|
+
languageCodes = language_codes
|
53
|
+
|
54
|
+
return Hash[languageCodes.map { |languageCode|
|
55
|
+
languageFromCode = Locale::Tag::Cldr.new(languageCode)
|
56
|
+
localizedLanguageObject = CLDR::Object.new(locale: languageFromCode, fallback: fallbackLanguage)
|
57
|
+
|
58
|
+
[languageCode, localizedLanguageObject.core.languages[languageCode]]
|
59
|
+
}]
|
60
|
+
else
|
61
|
+
localizationLanguageObject = CLDR::Object.new(locale: localizationLanguage, fallback: fallbackLanguage)
|
62
|
+
return localizationLanguageObject.core.languages
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def language(languageString)
|
69
|
+
defaultLanguageString = languageString ? languageString : DEFAULT_LANGUAGE_CODE
|
70
|
+
return Locale::Tag::Cldr.new(defaultLanguageString)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cldr-languages
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Florian Schäffler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Use language code 'zzx' for getting languages in its own language
|
42
|
+
email:
|
43
|
+
- ruby@schf.de
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- cldr-languages.gemspec
|
54
|
+
- lib/cldr/languages/version.rb
|
55
|
+
- lib/languages.rb
|
56
|
+
homepage: http://www.schf.de
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.1
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Localization of languages to a given language or its own language
|
80
|
+
test_files: []
|