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.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/cache/file_data_provider/countries-AB.txt +45 -45
  3. data/cache/file_data_provider/countries-AF.txt +6 -6
  4. data/cache/file_data_provider/countries-AK.txt +7 -7
  5. data/cache/file_data_provider/countries-AM.txt +25 -25
  6. data/cache/file_data_provider/countries-AN.txt +107 -107
  7. data/cache/file_data_provider/countries-AR.txt +2 -2
  8. data/cache/file_data_provider/countries-AS.txt +6 -6
  9. data/cache/file_data_provider/countries-AZ.txt +32 -32
  10. data/cache/file_data_provider/countries-BA.txt +185 -185
  11. data/cache/file_data_provider/countries-BE.txt +2 -2
  12. data/cache/file_data_provider/countries-BG.txt +4 -4
  13. data/cache/file_data_provider/countries-BI.txt +12 -12
  14. data/cache/file_data_provider/countries-BN.txt +2 -2
  15. data/cache/file_data_provider/countries-BN_IN.txt +2 -2
  16. data/cache/file_data_provider/countries-BR.txt +4 -4
  17. data/cache/file_data_provider/countries-BS.txt +5 -5
  18. data/cache/file_data_provider/countries-CA.txt +4 -4
  19. data/cache/file_data_provider/countries-CE.txt +3 -3
  20. data/cache/file_data_provider/countries-CS.txt +2 -2
  21. data/cache/file_data_provider/countries-CV.txt +3 -3
  22. data/cache/file_data_provider/countries-CY.txt +2 -2
  23. data/cache/file_data_provider/countries-DA.txt +2 -2
  24. data/cache/file_data_provider/countries-DV.txt +3 -3
  25. data/cache/file_data_provider/countries-DZ.txt +6 -6
  26. data/cache/file_data_provider/countries-EE.txt +11 -11
  27. data/cache/file_data_provider/countries-EL.txt +2 -2
  28. data/cache/file_data_provider/countries-ES.txt +2 -2
  29. data/cache/file_data_provider/countries-EU.txt +2 -2
  30. data/cache/file_data_provider/countries-FA.txt +2 -2
  31. data/cache/file_data_provider/countries-FI.txt +5 -5
  32. data/cache/file_data_provider/countries-FO.txt +4 -4
  33. data/cache/file_data_provider/countries-FY.txt +3 -3
  34. data/cache/file_data_provider/countries-GA.txt +4 -4
  35. data/cache/file_data_provider/countries-GL.txt +4 -4
  36. data/cache/file_data_provider/countries-GN.txt +5 -5
  37. data/cache/file_data_provider/countries-GV.txt +1 -1
  38. data/cache/file_data_provider/countries-HA.txt +1 -1
  39. data/cache/file_data_provider/countries-HT.txt +3 -3
  40. data/cache/file_data_provider/countries-HU.txt +2 -2
  41. data/cache/file_data_provider/countries-HY.txt +4 -4
  42. data/cache/file_data_provider/countries-IA.txt +2 -2
  43. data/cache/file_data_provider/countries-IO.txt +3 -3
  44. data/cache/file_data_provider/countries-IT.txt +2 -2
  45. data/cache/file_data_provider/countries-JA.txt +3 -3
  46. data/cache/file_data_provider/countries-KA.txt +7 -7
  47. data/cache/file_data_provider/countries-KI.txt +1 -1
  48. data/cache/file_data_provider/countries-KK.txt +4 -4
  49. data/cache/file_data_provider/countries-KL.txt +35 -35
  50. data/cache/file_data_provider/countries-KM.txt +3 -3
  51. data/cache/file_data_provider/countries-KN.txt +7 -7
  52. data/cache/file_data_provider/countries-KO.txt +2 -2
  53. data/cache/file_data_provider/countries-KV.txt +1 -1
  54. data/cache/file_data_provider/countries-KW.txt +3 -3
  55. data/cache/file_data_provider/countries-KY.txt +3 -3
  56. data/cache/file_data_provider/countries-LT.txt +5 -5
  57. data/cache/file_data_provider/countries-LV.txt +4 -4
  58. data/cache/file_data_provider/countries-MI.txt +16 -16
  59. data/cache/file_data_provider/countries-MK.txt +5 -5
  60. data/cache/file_data_provider/countries-ML.txt +7 -7
  61. data/cache/file_data_provider/countries-MN.txt +13 -13
  62. data/cache/file_data_provider/countries-MR.txt +2 -2
  63. data/cache/file_data_provider/countries-MS.txt +6 -6
  64. data/cache/file_data_provider/countries-MT.txt +21 -21
  65. data/cache/file_data_provider/countries-MY.txt +1 -1
  66. data/cache/file_data_provider/countries-NA.txt +1 -1
  67. data/cache/file_data_provider/countries-NE.txt +5 -5
  68. data/cache/file_data_provider/countries-NN.txt +5 -5
  69. data/cache/file_data_provider/countries-NV.txt +1 -1
  70. data/cache/file_data_provider/countries-OC.txt +2 -2
  71. data/cache/file_data_provider/countries-OR.txt +2 -2
  72. data/cache/file_data_provider/countries-PA.txt +2 -2
  73. data/cache/file_data_provider/countries-PI.txt +1 -1
  74. data/cache/file_data_provider/countries-PL.txt +2 -2
  75. data/cache/file_data_provider/countries-PS.txt +3 -3
  76. data/cache/file_data_provider/countries-PT.txt +2 -2
  77. data/cache/file_data_provider/countries-RO.txt +3 -3
  78. data/cache/file_data_provider/countries-RW.txt +6 -6
  79. data/cache/file_data_provider/countries-SD.txt +1 -1
  80. data/cache/file_data_provider/countries-SI.txt +4 -4
  81. data/cache/file_data_provider/countries-SK.txt +3 -3
  82. data/cache/file_data_provider/countries-SL.txt +4 -4
  83. data/cache/file_data_provider/countries-SO.txt +5 -5
  84. data/cache/file_data_provider/countries-SQ.txt +2 -2
  85. data/cache/file_data_provider/countries-SR.txt +2 -2
  86. data/cache/file_data_provider/countries-SW.txt +9 -9
  87. data/cache/file_data_provider/countries-TA.txt +7 -7
  88. data/cache/file_data_provider/countries-TE.txt +5 -5
  89. data/cache/file_data_provider/countries-TG.txt +2 -2
  90. data/cache/file_data_provider/countries-TH.txt +3 -3
  91. data/cache/file_data_provider/countries-TI.txt +5 -5
  92. data/cache/file_data_provider/countries-TK.txt +7 -7
  93. data/cache/file_data_provider/countries-TL.txt +4 -4
  94. data/cache/file_data_provider/countries-TT.txt +8 -8
  95. data/cache/file_data_provider/countries-UG.txt +2 -2
  96. data/cache/file_data_provider/countries-UR.txt +3 -3
  97. data/cache/file_data_provider/countries-UZ.txt +3 -3
  98. data/cache/file_data_provider/countries-VE.txt +25 -25
  99. data/cache/file_data_provider/countries-VI.txt +4 -4
  100. data/cache/file_data_provider/countries-WA.txt +4 -4
  101. data/cache/file_data_provider/countries-WO.txt +6 -6
  102. data/cache/file_data_provider/countries-XH.txt +60 -60
  103. data/cache/file_data_provider/countries-YO.txt +3 -3
  104. data/cache/file_data_provider/countries-ZH_HK.txt +2 -2
  105. data/cache/file_data_provider/countries-ZH_TW.txt +2 -2
  106. data/cache/file_data_provider/countries-ZU.txt +42 -42
  107. data/cache/file_data_provider/languages-AF.txt +28 -28
  108. data/cache/file_data_provider/languages-AM.txt +10 -10
  109. data/cache/file_data_provider/languages-AR.txt +32 -32
  110. data/cache/file_data_provider/languages-AS.txt +4 -4
  111. data/cache/file_data_provider/languages-AZ.txt +60 -60
  112. data/cache/file_data_provider/languages-BE.txt +2 -2
  113. data/cache/file_data_provider/languages-BG.txt +3 -3
  114. data/cache/file_data_provider/languages-BN.txt +1 -1
  115. data/cache/file_data_provider/languages-BR.txt +2 -2
  116. data/cache/file_data_provider/languages-BS.txt +27 -27
  117. data/cache/file_data_provider/languages-CA.txt +1 -1
  118. data/cache/file_data_provider/languages-CS.txt +2 -2
  119. data/cache/file_data_provider/languages-CY.txt +42 -42
  120. data/cache/file_data_provider/languages-DA.txt +2 -2
  121. data/cache/file_data_provider/languages-DE.txt +1 -1
  122. data/cache/file_data_provider/languages-EL.txt +7 -7
  123. data/cache/file_data_provider/languages-EO.txt +1 -1
  124. data/cache/file_data_provider/languages-ES.txt +1 -1
  125. data/cache/file_data_provider/languages-ET.txt +1 -1
  126. data/cache/file_data_provider/languages-FA.txt +21 -21
  127. data/cache/file_data_provider/languages-FI.txt +4 -4
  128. data/cache/file_data_provider/languages-FR.txt +2 -2
  129. data/cache/file_data_provider/languages-GA.txt +4 -4
  130. data/cache/file_data_provider/languages-GL.txt +4 -4
  131. data/cache/file_data_provider/languages-GU.txt +2 -2
  132. data/cache/file_data_provider/languages-HE.txt +26 -26
  133. data/cache/file_data_provider/languages-HI.txt +9 -9
  134. data/cache/file_data_provider/languages-HR.txt +2 -2
  135. data/cache/file_data_provider/languages-HU.txt +2 -2
  136. data/cache/file_data_provider/languages-ID.txt +2 -2
  137. data/cache/file_data_provider/languages-IS.txt +2 -2
  138. data/cache/file_data_provider/languages-IT.txt +2 -2
  139. data/cache/file_data_provider/languages-JA.txt +7 -7
  140. data/cache/file_data_provider/languages-KN.txt +5 -5
  141. data/cache/file_data_provider/languages-KO.txt +2 -2
  142. data/cache/file_data_provider/languages-LT.txt +5 -5
  143. data/cache/file_data_provider/languages-LV.txt +4 -4
  144. data/cache/file_data_provider/languages-MI.txt +62 -62
  145. data/cache/file_data_provider/languages-MK.txt +50 -50
  146. data/cache/file_data_provider/languages-ML.txt +5 -5
  147. data/cache/file_data_provider/languages-MN.txt +29 -29
  148. data/cache/file_data_provider/languages-MR.txt +2 -2
  149. data/cache/file_data_provider/languages-MS.txt +42 -42
  150. data/cache/file_data_provider/languages-MT.txt +55 -55
  151. data/cache/file_data_provider/languages-NB.txt +32 -32
  152. data/cache/file_data_provider/languages-NL.txt +2 -2
  153. data/cache/file_data_provider/languages-NN.txt +13 -13
  154. data/cache/file_data_provider/languages-OC.txt +3 -3
  155. data/cache/file_data_provider/languages-OR.txt +2 -2
  156. data/cache/file_data_provider/languages-PA.txt +2 -2
  157. data/cache/file_data_provider/languages-PL.txt +1 -1
  158. data/cache/file_data_provider/languages-PS.txt +1 -1
  159. data/cache/file_data_provider/languages-PT.txt +1 -1
  160. data/cache/file_data_provider/languages-PT_BR.txt +1 -1
  161. data/cache/file_data_provider/languages-RO.txt +4 -4
  162. data/cache/file_data_provider/languages-RU.txt +2 -2
  163. data/cache/file_data_provider/languages-RW.txt +25 -25
  164. data/cache/file_data_provider/languages-SC.txt +2 -2
  165. data/cache/file_data_provider/languages-SK.txt +1 -1
  166. data/cache/file_data_provider/languages-SL.txt +3 -3
  167. data/cache/file_data_provider/languages-SR.txt +2 -2
  168. data/cache/file_data_provider/languages-SV.txt +1 -1
  169. data/cache/file_data_provider/languages-TA.txt +5 -5
  170. data/cache/file_data_provider/languages-TE.txt +5 -5
  171. data/cache/file_data_provider/languages-TG.txt +2 -2
  172. data/cache/file_data_provider/languages-TH.txt +3 -3
  173. data/cache/file_data_provider/languages-TI.txt +9 -9
  174. data/cache/file_data_provider/languages-TR.txt +1 -1
  175. data/cache/file_data_provider/languages-TT.txt +17 -17
  176. data/cache/file_data_provider/languages-UK.txt +2 -2
  177. data/cache/file_data_provider/languages-VE.txt +30 -30
  178. data/cache/file_data_provider/languages-VI.txt +4 -4
  179. data/cache/file_data_provider/languages-WA.txt +3 -3
  180. data/cache/file_data_provider/languages-XH.txt +41 -41
  181. data/cache/file_data_provider/languages-ZH_CN.txt +1 -1
  182. data/cache/file_data_provider/languages-ZH_HK.txt +2 -2
  183. data/cache/file_data_provider/languages-ZH_TW.txt +1 -1
  184. data/cache/file_data_provider/languages-ZU.txt +42 -42
  185. data/lib/i18n_data/live_data_provider.rb +50 -19
  186. data/lib/i18n_data/version.rb +1 -1
  187. 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("english_#{type}").map do |code, name|
54
- [code, translate(type, name, language_code) || name]
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
- data = get(url)
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
- data = data.force_encoding('utf-8') if data.respond_to?(:force_encoding) # 1.9
74
- data = data.split("\n")
75
- po_to_hash data
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 po_to_hash(data)
105
- names = data.select{|l| l =~ /^msgid/ }.map{|line| line.match(/^msgid "(.*?)"/)[1] }
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)
@@ -1,3 +1,3 @@
1
1
  module I18nData
2
- VERSION = Version = "0.14.0"
2
+ VERSION = Version = "0.15.0"
3
3
  end
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.14.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-16 00:00:00.000000000 Z
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: []