i18n_data 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cache/file_data_provider/countries-AB.txt +45 -45
- data/cache/file_data_provider/countries-AF.txt +6 -6
- data/cache/file_data_provider/countries-AK.txt +7 -7
- data/cache/file_data_provider/countries-AM.txt +25 -25
- data/cache/file_data_provider/countries-AN.txt +107 -107
- data/cache/file_data_provider/countries-AR.txt +2 -2
- data/cache/file_data_provider/countries-AS.txt +6 -6
- data/cache/file_data_provider/countries-AZ.txt +32 -32
- data/cache/file_data_provider/countries-BA.txt +185 -185
- data/cache/file_data_provider/countries-BE.txt +2 -2
- data/cache/file_data_provider/countries-BG.txt +4 -4
- data/cache/file_data_provider/countries-BI.txt +12 -12
- data/cache/file_data_provider/countries-BN.txt +2 -2
- data/cache/file_data_provider/countries-BN_IN.txt +2 -2
- data/cache/file_data_provider/countries-BR.txt +4 -4
- data/cache/file_data_provider/countries-BS.txt +5 -5
- data/cache/file_data_provider/countries-CA.txt +4 -4
- data/cache/file_data_provider/countries-CE.txt +3 -3
- data/cache/file_data_provider/countries-CS.txt +2 -2
- data/cache/file_data_provider/countries-CV.txt +3 -3
- data/cache/file_data_provider/countries-CY.txt +2 -2
- data/cache/file_data_provider/countries-DA.txt +2 -2
- data/cache/file_data_provider/countries-DV.txt +3 -3
- data/cache/file_data_provider/countries-DZ.txt +6 -6
- data/cache/file_data_provider/countries-EE.txt +11 -11
- data/cache/file_data_provider/countries-EL.txt +2 -2
- data/cache/file_data_provider/countries-ES.txt +2 -2
- data/cache/file_data_provider/countries-EU.txt +2 -2
- data/cache/file_data_provider/countries-FA.txt +2 -2
- data/cache/file_data_provider/countries-FI.txt +5 -5
- data/cache/file_data_provider/countries-FO.txt +4 -4
- data/cache/file_data_provider/countries-FY.txt +3 -3
- data/cache/file_data_provider/countries-GA.txt +4 -4
- data/cache/file_data_provider/countries-GL.txt +4 -4
- data/cache/file_data_provider/countries-GN.txt +5 -5
- data/cache/file_data_provider/countries-GV.txt +1 -1
- data/cache/file_data_provider/countries-HA.txt +1 -1
- data/cache/file_data_provider/countries-HT.txt +3 -3
- data/cache/file_data_provider/countries-HU.txt +2 -2
- data/cache/file_data_provider/countries-HY.txt +4 -4
- data/cache/file_data_provider/countries-IA.txt +2 -2
- data/cache/file_data_provider/countries-IO.txt +3 -3
- data/cache/file_data_provider/countries-IT.txt +2 -2
- data/cache/file_data_provider/countries-JA.txt +3 -3
- data/cache/file_data_provider/countries-KA.txt +7 -7
- data/cache/file_data_provider/countries-KI.txt +1 -1
- data/cache/file_data_provider/countries-KK.txt +4 -4
- data/cache/file_data_provider/countries-KL.txt +35 -35
- data/cache/file_data_provider/countries-KM.txt +3 -3
- data/cache/file_data_provider/countries-KN.txt +7 -7
- data/cache/file_data_provider/countries-KO.txt +2 -2
- data/cache/file_data_provider/countries-KV.txt +1 -1
- data/cache/file_data_provider/countries-KW.txt +3 -3
- data/cache/file_data_provider/countries-KY.txt +3 -3
- data/cache/file_data_provider/countries-LT.txt +5 -5
- data/cache/file_data_provider/countries-LV.txt +4 -4
- data/cache/file_data_provider/countries-MI.txt +16 -16
- data/cache/file_data_provider/countries-MK.txt +5 -5
- data/cache/file_data_provider/countries-ML.txt +7 -7
- data/cache/file_data_provider/countries-MN.txt +13 -13
- data/cache/file_data_provider/countries-MR.txt +2 -2
- data/cache/file_data_provider/countries-MS.txt +6 -6
- data/cache/file_data_provider/countries-MT.txt +21 -21
- data/cache/file_data_provider/countries-MY.txt +1 -1
- data/cache/file_data_provider/countries-NA.txt +1 -1
- data/cache/file_data_provider/countries-NE.txt +5 -5
- data/cache/file_data_provider/countries-NN.txt +5 -5
- data/cache/file_data_provider/countries-NV.txt +1 -1
- data/cache/file_data_provider/countries-OC.txt +2 -2
- data/cache/file_data_provider/countries-OR.txt +2 -2
- data/cache/file_data_provider/countries-PA.txt +2 -2
- data/cache/file_data_provider/countries-PI.txt +1 -1
- data/cache/file_data_provider/countries-PL.txt +2 -2
- data/cache/file_data_provider/countries-PS.txt +3 -3
- data/cache/file_data_provider/countries-PT.txt +2 -2
- data/cache/file_data_provider/countries-RO.txt +3 -3
- data/cache/file_data_provider/countries-RW.txt +6 -6
- data/cache/file_data_provider/countries-SD.txt +1 -1
- data/cache/file_data_provider/countries-SI.txt +4 -4
- data/cache/file_data_provider/countries-SK.txt +3 -3
- data/cache/file_data_provider/countries-SL.txt +4 -4
- data/cache/file_data_provider/countries-SO.txt +5 -5
- data/cache/file_data_provider/countries-SQ.txt +2 -2
- data/cache/file_data_provider/countries-SR.txt +2 -2
- data/cache/file_data_provider/countries-SW.txt +9 -9
- data/cache/file_data_provider/countries-TA.txt +7 -7
- data/cache/file_data_provider/countries-TE.txt +5 -5
- data/cache/file_data_provider/countries-TG.txt +2 -2
- data/cache/file_data_provider/countries-TH.txt +3 -3
- data/cache/file_data_provider/countries-TI.txt +5 -5
- data/cache/file_data_provider/countries-TK.txt +7 -7
- data/cache/file_data_provider/countries-TL.txt +4 -4
- data/cache/file_data_provider/countries-TT.txt +8 -8
- data/cache/file_data_provider/countries-UG.txt +2 -2
- data/cache/file_data_provider/countries-UR.txt +3 -3
- data/cache/file_data_provider/countries-UZ.txt +3 -3
- data/cache/file_data_provider/countries-VE.txt +25 -25
- data/cache/file_data_provider/countries-VI.txt +4 -4
- data/cache/file_data_provider/countries-WA.txt +4 -4
- data/cache/file_data_provider/countries-WO.txt +6 -6
- data/cache/file_data_provider/countries-XH.txt +60 -60
- data/cache/file_data_provider/countries-YO.txt +3 -3
- data/cache/file_data_provider/countries-ZH_HK.txt +2 -2
- data/cache/file_data_provider/countries-ZH_TW.txt +2 -2
- data/cache/file_data_provider/countries-ZU.txt +42 -42
- data/cache/file_data_provider/languages-AF.txt +28 -28
- data/cache/file_data_provider/languages-AM.txt +10 -10
- data/cache/file_data_provider/languages-AR.txt +32 -32
- data/cache/file_data_provider/languages-AS.txt +4 -4
- data/cache/file_data_provider/languages-AZ.txt +60 -60
- data/cache/file_data_provider/languages-BE.txt +2 -2
- data/cache/file_data_provider/languages-BG.txt +3 -3
- data/cache/file_data_provider/languages-BN.txt +1 -1
- data/cache/file_data_provider/languages-BR.txt +2 -2
- data/cache/file_data_provider/languages-BS.txt +27 -27
- data/cache/file_data_provider/languages-CA.txt +1 -1
- data/cache/file_data_provider/languages-CS.txt +2 -2
- data/cache/file_data_provider/languages-CY.txt +42 -42
- data/cache/file_data_provider/languages-DA.txt +2 -2
- data/cache/file_data_provider/languages-DE.txt +1 -1
- data/cache/file_data_provider/languages-EL.txt +7 -7
- data/cache/file_data_provider/languages-EO.txt +1 -1
- data/cache/file_data_provider/languages-ES.txt +1 -1
- data/cache/file_data_provider/languages-ET.txt +1 -1
- data/cache/file_data_provider/languages-FA.txt +21 -21
- data/cache/file_data_provider/languages-FI.txt +4 -4
- data/cache/file_data_provider/languages-FR.txt +2 -2
- data/cache/file_data_provider/languages-GA.txt +4 -4
- data/cache/file_data_provider/languages-GL.txt +4 -4
- data/cache/file_data_provider/languages-GU.txt +2 -2
- data/cache/file_data_provider/languages-HE.txt +26 -26
- data/cache/file_data_provider/languages-HI.txt +9 -9
- data/cache/file_data_provider/languages-HR.txt +2 -2
- data/cache/file_data_provider/languages-HU.txt +2 -2
- data/cache/file_data_provider/languages-ID.txt +2 -2
- data/cache/file_data_provider/languages-IS.txt +2 -2
- data/cache/file_data_provider/languages-IT.txt +2 -2
- data/cache/file_data_provider/languages-JA.txt +7 -7
- data/cache/file_data_provider/languages-KN.txt +5 -5
- data/cache/file_data_provider/languages-KO.txt +2 -2
- data/cache/file_data_provider/languages-LT.txt +5 -5
- data/cache/file_data_provider/languages-LV.txt +4 -4
- data/cache/file_data_provider/languages-MI.txt +62 -62
- data/cache/file_data_provider/languages-MK.txt +50 -50
- data/cache/file_data_provider/languages-ML.txt +5 -5
- data/cache/file_data_provider/languages-MN.txt +29 -29
- data/cache/file_data_provider/languages-MR.txt +2 -2
- data/cache/file_data_provider/languages-MS.txt +42 -42
- data/cache/file_data_provider/languages-MT.txt +55 -55
- data/cache/file_data_provider/languages-NB.txt +32 -32
- data/cache/file_data_provider/languages-NL.txt +2 -2
- data/cache/file_data_provider/languages-NN.txt +13 -13
- data/cache/file_data_provider/languages-OC.txt +3 -3
- data/cache/file_data_provider/languages-OR.txt +2 -2
- data/cache/file_data_provider/languages-PA.txt +2 -2
- data/cache/file_data_provider/languages-PL.txt +1 -1
- data/cache/file_data_provider/languages-PS.txt +1 -1
- data/cache/file_data_provider/languages-PT.txt +1 -1
- data/cache/file_data_provider/languages-PT_BR.txt +1 -1
- data/cache/file_data_provider/languages-RO.txt +4 -4
- data/cache/file_data_provider/languages-RU.txt +2 -2
- data/cache/file_data_provider/languages-RW.txt +25 -25
- data/cache/file_data_provider/languages-SC.txt +2 -2
- data/cache/file_data_provider/languages-SK.txt +1 -1
- data/cache/file_data_provider/languages-SL.txt +3 -3
- data/cache/file_data_provider/languages-SR.txt +2 -2
- data/cache/file_data_provider/languages-SV.txt +1 -1
- data/cache/file_data_provider/languages-TA.txt +5 -5
- data/cache/file_data_provider/languages-TE.txt +5 -5
- data/cache/file_data_provider/languages-TG.txt +2 -2
- data/cache/file_data_provider/languages-TH.txt +3 -3
- data/cache/file_data_provider/languages-TI.txt +9 -9
- data/cache/file_data_provider/languages-TR.txt +1 -1
- data/cache/file_data_provider/languages-TT.txt +17 -17
- data/cache/file_data_provider/languages-UK.txt +2 -2
- data/cache/file_data_provider/languages-VE.txt +30 -30
- data/cache/file_data_provider/languages-VI.txt +4 -4
- data/cache/file_data_provider/languages-WA.txt +3 -3
- data/cache/file_data_provider/languages-XH.txt +41 -41
- data/cache/file_data_provider/languages-ZH_CN.txt +1 -1
- data/cache/file_data_provider/languages-ZH_HK.txt +2 -2
- data/cache/file_data_provider/languages-ZH_TW.txt +1 -1
- data/cache/file_data_provider/languages-ZU.txt +42 -42
- data/lib/i18n_data/live_data_provider.rb +50 -19
- data/lib/i18n_data/version.rb +1 -1
- metadata +17 -3
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'simple_po_parser'
|
2
3
|
|
3
4
|
module I18nData
|
4
5
|
# fetches data online from debian git
|
@@ -42,20 +43,21 @@ module I18nData
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
|
-
def translate(type, language, to_language_code)
|
46
|
-
translated = translations(type, to_language_code)[language]
|
47
|
-
translated.to_s.empty? ? nil : translated
|
48
|
-
end
|
49
|
-
|
50
46
|
def translated(type, language_code)
|
51
47
|
@translated ||= {}
|
48
|
+
|
52
49
|
@translated["#{type}_#{language_code}"] ||= begin
|
53
|
-
Hash[send("
|
54
|
-
[
|
50
|
+
Hash[send("alpha_codes_for_#{type}").map do |alpha2, alpha3|
|
51
|
+
[alpha2, translate(type, alpha3, language_code) || fallback_name(type, alpha3)]
|
55
52
|
end]
|
56
53
|
end
|
57
54
|
end
|
58
55
|
|
56
|
+
def translate(type, alpha3, to_language_code)
|
57
|
+
translated = translations(type, to_language_code)[alpha3]
|
58
|
+
translated.to_s.empty? ? nil : translated
|
59
|
+
end
|
60
|
+
|
59
61
|
def translations(type, language_code)
|
60
62
|
@translations ||= {}
|
61
63
|
@translations["#{type}_#{language_code}"] ||= begin
|
@@ -63,16 +65,50 @@ module I18nData
|
|
63
65
|
code[0].downcase!
|
64
66
|
code = code.join("_")
|
65
67
|
|
66
|
-
url = TRANSLATIONS[type]+"#{code}.po"
|
67
68
|
begin
|
68
|
-
|
69
|
+
file_path = "#{CLONE_DEST}/#{TRANSLATIONS[type]}#{code}.po"
|
70
|
+
data = SimplePoParser.parse(file_path)
|
71
|
+
data = data[1..-1] # Remove the initial info block in the .po file
|
72
|
+
|
73
|
+
# Prefer the "Common name for" blocks, but fallback to "Name for" blocks
|
74
|
+
common_names = get_po_data(data, 'Common name for')
|
75
|
+
fallback_names = get_po_data(data, 'Name for')
|
76
|
+
|
77
|
+
fallback_names.merge(common_names)
|
69
78
|
rescue Errno::ENOENT
|
70
79
|
raise NoTranslationAvailable, "for #{type} and language code = #{code} (#{$!})"
|
71
80
|
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_po_data(data, extracted_comment_string)
|
85
|
+
# Ignores the 'fuzzy' entries
|
86
|
+
po_entries = data.select do |t|
|
87
|
+
t[:extracted_comment].start_with?(extracted_comment_string) && t[:flag] != 'fuzzy'
|
88
|
+
end
|
89
|
+
|
90
|
+
# Maps over the alpha3 country code in the 'extracted_comment'
|
91
|
+
# Eg: "Name for GBR"
|
92
|
+
po_entries.map.with_object({}) do |t, translations|
|
93
|
+
alpha3 = t[:extracted_comment][-3..-1].upcase
|
94
|
+
translation = t[:msgstr]
|
95
|
+
translations[alpha3] = translation.is_a?(Array) ? translation.join : translation
|
96
|
+
end
|
97
|
+
end
|
72
98
|
|
73
|
-
|
74
|
-
|
75
|
-
|
99
|
+
def alpha_codes_for_countries
|
100
|
+
@alpha_codes_for_countries ||= json(:countries)['3166-1'].each_with_object({}) do |entry, codes|
|
101
|
+
alpha2 = entry['alpha_2']&.upcase
|
102
|
+
alpha3 = entry['alpha_3']&.upcase
|
103
|
+
codes[alpha2] = alpha3 unless alpha2.nil?
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def alpha_codes_for_languages
|
108
|
+
@alpha_codes_for_languages ||= json(:languages)['639-2'].each_with_object({}) do |entry, codes|
|
109
|
+
alpha2 = entry['alpha_2']&.upcase
|
110
|
+
alpha3 = entry['alpha_3']&.upcase
|
111
|
+
codes[alpha2] = alpha3 unless alpha2.nil?
|
76
112
|
end
|
77
113
|
end
|
78
114
|
|
@@ -101,13 +137,8 @@ module I18nData
|
|
101
137
|
end
|
102
138
|
end
|
103
139
|
|
104
|
-
def
|
105
|
-
|
106
|
-
translations = data.select{|l| l =~ /^msgstr/ }.map{|line| line.match(/^msgstr "(.*?)"/)[1] }
|
107
|
-
|
108
|
-
Hash[names.each_with_index.map do |name,index|
|
109
|
-
[name, translations[index]]
|
110
|
-
end]
|
140
|
+
def fallback_name(type, alpha3)
|
141
|
+
send("english_#{type}")[send("alpha_codes_for_#{type}").invert[alpha3]]
|
111
142
|
end
|
112
143
|
|
113
144
|
def get(url)
|
data/lib/i18n_data/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: simple_po_parser
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
13
27
|
description:
|
14
28
|
email: michael@grosser.it
|
15
29
|
executables: []
|