loco_strings 0.1.4.1 → 0.1.5
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 +4 -4
- data/lib/loco_strings/decoders/xcstrings_decoder.rb +3 -1
- data/lib/loco_strings/encoders/xcstrings_encoder.rb +30 -9
- data/lib/loco_strings/parsers/xcstrings_file.rb +4 -0
- data/lib/loco_strings/version.rb +1 -1
- data/lib/loco_strings.rb +25 -13
- data/loco_strings.gemspec +41 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b08530cf06fde825bb19978db9b25c6dd2def7fed991f7e3cc7769d24efafd34
|
4
|
+
data.tar.gz: 7fb65903ab8dcdcd5b20b6072ac6dc7934d994ff6353c857b144549a54a83953
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e3c576ffdca90cf4e046dfc0c5f977538ca34504637d7d8b691063206f7c12ecb2f5a330fd26bb39647625652585dc33013364abdda23bf4833464a33e2ddcd
|
7
|
+
data.tar.gz: f49f067641e258367ebcc367121cc30b27feb062ea0fb42716f74c9d40ff622e1f1d397e4b3f308a6bfaf64a65ce53cccc27716126b4d1adf46fbc9f52b96d04
|
@@ -43,9 +43,11 @@ module LocoStrings
|
|
43
43
|
def decode_strings(json)
|
44
44
|
strings = json["strings"]
|
45
45
|
strings.each do |key, value|
|
46
|
+
translatable = value.fetch("shouldTranslate", true)
|
46
47
|
val = decode_string(key, value, @language)
|
47
48
|
@strings[key] = val if val
|
48
49
|
@strings[key] = LocoString.new(key, key, value["comment"], "new") if val.nil?
|
50
|
+
@strings[key].translatable = translatable
|
49
51
|
|
50
52
|
decode_translations(key, value)
|
51
53
|
end
|
@@ -77,7 +79,7 @@ module LocoStrings
|
|
77
79
|
plural = decode_plural(variations, comment)
|
78
80
|
return nil if plural.empty?
|
79
81
|
|
80
|
-
variation = LocoVariantions.new(key, comment)
|
82
|
+
variation = LocoVariantions.new(key, nil, comment)
|
81
83
|
plural.each do |unit|
|
82
84
|
variation.append_string(unit)
|
83
85
|
end
|
@@ -40,19 +40,40 @@ module LocoStrings
|
|
40
40
|
|
41
41
|
def encode_key(key)
|
42
42
|
row = {}
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
value = translation[key]
|
47
|
-
next if value.nil?
|
48
|
-
|
49
|
-
row["comment"] = value.comment unless row.key?("comment") || value.comment.nil?
|
50
|
-
row["localizations"] ||= {}
|
51
|
-
row["localizations"][language] = encode_value(value)
|
43
|
+
sorted_keys.each do |language|
|
44
|
+
process_language(row, language, key)
|
52
45
|
end
|
53
46
|
row
|
54
47
|
end
|
55
48
|
|
49
|
+
def sorted_keys
|
50
|
+
@translations.keys.sort_by(&:to_s)
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_language(row, language, key)
|
54
|
+
return unless @translations[language].key?(key)
|
55
|
+
|
56
|
+
value = @translations[language][key]
|
57
|
+
return if value.nil?
|
58
|
+
|
59
|
+
add_comment(row, value)
|
60
|
+
add_localization(row, language, value)
|
61
|
+
add_translation_flag(row, value)
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_comment(row, value)
|
65
|
+
row["comment"] = value.comment unless row.key?("comment") || value.comment.nil?
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_localization(row, language, value)
|
69
|
+
row["localizations"] ||= {}
|
70
|
+
row["localizations"][language] = encode_value(value)
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_translation_flag(row, value)
|
74
|
+
row["shouldTranslate"] = false if value.translatable == false
|
75
|
+
end
|
76
|
+
|
56
77
|
def encode_value(value)
|
57
78
|
if value.is_a?(LocoVariantions)
|
58
79
|
encode_variations(value)
|
@@ -52,6 +52,10 @@ module LocoStrings
|
|
52
52
|
@strings[key] = variations if @language == language
|
53
53
|
end
|
54
54
|
|
55
|
+
def update_traslatability(key, translatable)
|
56
|
+
@strings[key].translatable = translatable
|
57
|
+
end
|
58
|
+
|
55
59
|
def select_language(language)
|
56
60
|
raise Error, "The base language is aready defined" unless @language.nil?
|
57
61
|
|
data/lib/loco_strings/version.rb
CHANGED
data/lib/loco_strings.rb
CHANGED
@@ -9,42 +9,54 @@ require_relative "loco_strings/parsers/xcstrings_file"
|
|
9
9
|
module LocoStrings
|
10
10
|
class Error < StandardError; end
|
11
11
|
|
12
|
-
LocoString = Struct.new(:key, :value, :comment, :state) do
|
13
|
-
def initialize(key, value, comment = nil, state = nil)
|
14
|
-
|
12
|
+
LocoString = Struct.new(:key, :value, :comment, :state, :translatable) do
|
13
|
+
def initialize(key, value, comment = nil, state = nil, translatable = nil)
|
14
|
+
translatable = true if translatable.nil?
|
15
|
+
super(key, value, comment, state, translatable)
|
15
16
|
end
|
16
17
|
|
17
|
-
def update(value, comment = nil, state = nil)
|
18
|
+
def update(value, comment = nil, state = nil, translatable = nil)
|
18
19
|
self.value = value
|
19
20
|
self.comment = comment unless comment.nil?
|
20
21
|
self.state = state
|
22
|
+
self.translatable = translatable unless translatable.nil?
|
21
23
|
end
|
22
24
|
|
23
25
|
def to_s
|
24
|
-
|
26
|
+
if translatable
|
27
|
+
"Key: #{key}, Value: #{value}, Comment: #{comment || "None"}, " \
|
28
|
+
"State: #{state || "None"}"
|
29
|
+
else
|
30
|
+
"Key: #{key}, Value: #{value}, Comment: #{comment || "None"}, " \
|
31
|
+
"State: #{state || "None"}, Translatable: #{translatable}"
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
28
|
-
LocoVariantions = Struct.new(:key, :strings, :comment) do
|
29
|
-
def initialize(key, strings = nil, comment = nil)
|
30
|
-
super
|
31
|
-
self.strings = strings || {}
|
36
|
+
LocoVariantions = Struct.new(:key, :strings, :comment, :translatable) do
|
37
|
+
def initialize(key, strings = nil, comment = nil, translatable = nil)
|
38
|
+
super(key, strings || {}, comment, translatable || true)
|
32
39
|
end
|
33
40
|
|
34
41
|
def append_string(string)
|
35
42
|
strings[string.key] = string
|
36
43
|
end
|
37
44
|
|
38
|
-
def update_variant(key, value, comment = nil, state = nil)
|
45
|
+
def update_variant(key, value, comment = nil, state = nil, translatable = nil)
|
39
46
|
if strings.key? key
|
40
|
-
strings[key].update(value, comment, state)
|
47
|
+
strings[key].update(value, comment, state, translatable)
|
41
48
|
else
|
42
|
-
strings[key] = LocoString.new(key, value, comment, state)
|
49
|
+
strings[key] = LocoString.new(key, value, comment, state, nil, translatable)
|
43
50
|
end
|
44
51
|
end
|
45
52
|
|
46
53
|
def to_s
|
47
|
-
|
54
|
+
if translatable
|
55
|
+
"Key: #{key}, Strings: #{strings}, Comment: #{comment || "None"}"
|
56
|
+
else
|
57
|
+
"Key: #{key}, Strings: #{strings}, Comment: #{comment || "None"}, " \
|
58
|
+
"Translatable: #{translatable}"
|
59
|
+
end
|
48
60
|
end
|
49
61
|
end
|
50
62
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Layout/LineLength
|
4
|
+
|
5
|
+
require_relative "lib/loco_strings/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "loco_strings"
|
9
|
+
spec.version = LocoStrings::VERSION
|
10
|
+
spec.authors = ["Aleksei Cherepanov"]
|
11
|
+
spec.email = ["ftp27host@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = "LocoStrings is a Ruby gem for working with iOS and Android localization strings."
|
14
|
+
spec.description = "LocoStrings is a powerful and easy-to-use Ruby gem that simplifies the process of managing localization strings for iOS and Android apps. With LocoStrings, you can easily extract, organize, and update your app's localized strings in one place, making it easy to maintain consistency across all of your app's translations. LocoStrings supports multiple file formats, including XLIFF and CSV, and provides a simple and intuitive API for working with your app's strings in code. Whether you're a solo developer or part of a team, LocoStrings makes managing your app's localization a breeze."
|
15
|
+
spec.homepage = "https://github.com/ftp27/loco_strings"
|
16
|
+
spec.license = "MIT"
|
17
|
+
spec.required_ruby_version = ">= 2.6.0"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
# Uncomment to register a new dependency of your gem
|
34
|
+
spec.add_dependency "nokogiri", "~> 1.13", ">= 1.13.8"
|
35
|
+
|
36
|
+
# For more information and examples about making a new gem, check out our
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
38
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
39
|
+
end
|
40
|
+
|
41
|
+
# rubocop:enable Layout/LineLength
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loco_strings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Cherepanov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/loco_strings/parsers/loco_file.rb
|
61
61
|
- lib/loco_strings/parsers/xcstrings_file.rb
|
62
62
|
- lib/loco_strings/version.rb
|
63
|
+
- loco_strings.gemspec
|
63
64
|
- sig/loco_strings.rbs
|
64
65
|
homepage: https://github.com/ftp27/loco_strings
|
65
66
|
licenses:
|