translation 1.30 → 1.31

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c549c4dffebafe002a5ee128ef1fdfd695f1d829db5f888878e002d50208d59b
4
- data.tar.gz: c4f73bdff11f801c63fda611f00c9b1a1c122c323527e21f730bcd888dc8fe07
3
+ metadata.gz: 186fe35e21fca5df7945cce6f444396496bfafeafacad620c9f3ddfc4870f238
4
+ data.tar.gz: 63f7e4ffd3ff3634ca1601d5aafd9f9ca6e029b78a60ffcc4cc1ca164056661d
5
5
  SHA512:
6
- metadata.gz: c2a10e981f76aaa817e1e88f7fa020f406cbd77e0bc79781d8b13d74310fe01e7eb5ac290b871d370729b228178e45f245a822194ed6007c2341ee99d90ec449
7
- data.tar.gz: 2198c2eb0111f19194a9641564c037e172c895fc7c6877a05b0fc8b2514c43ee536732614fd2b98470565194f6854f913231833c74af33f866b414e5dc9f4639
6
+ metadata.gz: 95d72a1cf231462570c6e9fd8fa67055b6245b4b76f733b2398ebfc484c7885199c57651973a85af47c2d413eaae8eed43762ee0aed7b72d1909c0fe7268e0a2
7
+ data.tar.gz: 142b2e7206fff2e3eafc2d3581396aaa37ad6c6acf64869d99a2e83f7ac12a3286d048e1b26250de25a1f96f631c058398a66c1e0eb7d9c3db0fe2cbfe868333
data/README.md CHANGED
@@ -52,6 +52,7 @@ Table of contents
52
52
  * [Paths where locales are stored (not recommended)](#paths-where-locales-are-stored-not-recommended)
53
53
  * [GetText Object Class Monkey-Patching](#gettext-object-class-monkey-patching)
54
54
  * [Pure Ruby (without Rails)](#pure-ruby-without-rails)
55
+ * [Limitations](#limitations)
55
56
  * [Testing](#testing)
56
57
  * [Contributing](#contributing)
57
58
  * [List of clients for Translation.io](#list-of-clients-for-translationio)
@@ -582,6 +583,33 @@ This gem was created specifically for Rails, but you can also use it in a pure R
582
583
 
583
584
  (Thanks [@kubaw](https://github.com/kubaw) for this snippet!)
584
585
 
586
+ ## Limitations
587
+
588
+ If you localize `.erb` files with the [GetText syntax](#gettext), please avoid
589
+ the use of `case` and `when` that are not correctly parsed by ERB.
590
+
591
+ This syntax will break and your file will be ignored:
592
+
593
+ ```erb
594
+ <% case @state %>
595
+ <% when 'received' %>
596
+ ```
597
+
598
+ Instead, use `if`/`elsif` or this `case` syntax:
599
+
600
+ ```erb
601
+ <%
602
+ case @state
603
+ when 'received'
604
+ %>
605
+ ```
606
+
607
+ These are the related discussions: [ruby/erb#4](https://github.com/ruby/erb/issues/4) and [translation/rails#44](https://github.com/translation/rails/issues/44).
608
+
609
+ There is currently an open PR ([ruby-gettext/gettext#91](https://github.com/ruby-gettext/gettext/pull/91)), switching ERB for [Erubi](https://github.com/jeremyevans/erubi),
610
+ that is waiting to be merged into GetText, but it may have unknown undesirable
611
+ side effects.
612
+
585
613
  ## Testing
586
614
 
587
615
  To run the specs:
data/lib/translation.rb CHANGED
@@ -93,6 +93,15 @@ module TranslationIO
93
93
  File.expand_path(relative_or_absolute_path).gsub("#{Dir.pwd}/", '')
94
94
  end
95
95
 
96
+ # Cf. https://github.com/translation/rails/issues/47
97
+ def yaml_load(source)
98
+ begin
99
+ YAML.load(source, :aliases => true) || {}
100
+ rescue ArgumentError
101
+ YAML.load(source) || {}
102
+ end
103
+ end
104
+
96
105
  def version
97
106
  Gem::Specification::find_by_name('translation').version.to_s
98
107
  end
@@ -43,7 +43,7 @@ module TranslationIO
43
43
 
44
44
  # To have a localization.xx.yml file during tests (without call to backend)
45
45
  if TranslationIO.config.test
46
- if YAML::load(yaml_data).present?
46
+ if TranslationIO.yaml_load(yaml_data).present?
47
47
  File.open(yaml_path, 'wb') do |file|
48
48
  file.write(self.class.top_comment)
49
49
  file.write(yaml_data)
@@ -64,7 +64,7 @@ module TranslationIO
64
64
  yaml_path = File.join(@yaml_locales_path, "localization.#{target_locale}.yml")
65
65
  yaml_data = parsed_response["yaml_data_#{target_locale}"]
66
66
 
67
- if yaml_data.present? && YAML::load(yaml_data).present?
67
+ if yaml_data.present? && TranslationIO.yaml_load(yaml_data).present?
68
68
  File.open(yaml_path, 'wb') do |file|
69
69
  file.write(self.class.top_comment)
70
70
  file.write(yaml_data)
@@ -13,7 +13,7 @@ module TranslationIO
13
13
  @yaml_file_paths.each do |locale_file_path|
14
14
  if locale_file_removable?(locale_file_path)
15
15
  if File.exist?(locale_file_path)
16
- content_hash = YAML::load(File.read(locale_file_path)) || {}
16
+ content_hash = TranslationIO.yaml_load(File.read(locale_file_path)) || {}
17
17
  source_content_hash = content_hash.select { |k| k.to_s == @source_locale.to_s }
18
18
 
19
19
  if source_content_hash.empty?
@@ -18,7 +18,7 @@ module TranslationIO
18
18
 
19
19
  @yaml_file_paths.each do |file_path|
20
20
  TranslationIO.info file_path, 2, 2
21
- file_translations = YAML::load(File.read(file_path))
21
+ file_translations = TranslationIO.yaml_load(File.read(file_path))
22
22
 
23
23
  unless file_translations.blank?
24
24
  all_translations = all_translations.deep_merge(file_translations)
@@ -46,7 +46,7 @@ module TranslationIO
46
46
  if yaml_sources_reload_needed?
47
47
  @yaml_sources = sort_by_project_locales_first(@yaml_file_paths).collect do |yaml_file_path|
48
48
  yaml_content = File.read(yaml_file_path)
49
- yaml_hash = YAML::load(yaml_content)
49
+ yaml_hash = TranslationIO.yaml_load(yaml_content)
50
50
  yaml_flat_hash = FlatHash.to_flat_hash(yaml_hash)
51
51
 
52
52
  {
@@ -138,7 +138,7 @@ module TranslationIO
138
138
  timestamps = metadata_content.scan(/timestamp: (\d*)/).flatten.uniq.collect(&:to_i)
139
139
  return timestamps.min || 0
140
140
  else
141
- return YAML::load(metadata_content)['timestamp'] rescue 0
141
+ return YAML.load(metadata_content)['timestamp'] rescue 0
142
142
  end
143
143
  else
144
144
  return 0
@@ -14,7 +14,7 @@ module TranslationIO
14
14
 
15
15
  @yaml_file_paths.each do |file_path|
16
16
  TranslationIO.info file_path, 2, 2
17
- file_translations = YAML::load(File.read(file_path))
17
+ file_translations = TranslationIO.yaml_load(File.read(file_path))
18
18
 
19
19
  unless file_translations.blank?
20
20
  all_translations = all_translations.deep_merge(file_translations)
@@ -26,7 +26,7 @@ module TranslationIO
26
26
  end
27
27
 
28
28
  def get_flat_translations_for_yaml_data(yaml_data)
29
- translations = YAML::load(yaml_data)
29
+ translations = TranslationIO.yaml_load(yaml_data)
30
30
 
31
31
  if translations
32
32
  return FlatHash.to_flat_hash(translations)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translation
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.30'
4
+ version: '1.31'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hoste
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-03-23 00:00:00.000000000 Z
12
+ date: 2022-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gettext