loco_strings 0.1.5 → 0.1.6
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 83291f99249e590483aa4c51d5710eada7bc80a910048bf0ba20b66a25ff187f
|
|
4
|
+
data.tar.gz: 11a3bbb921de0df05fe594518b98a254dc27531a8c312e383827090fb6816391
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 36f248bd8877845fa3983df90cf0903ca7fb26df5fefaeff0a52c98a5b5393e0d1e9a7121bc068db6b0c169b78899796807dabc119c45616d5ce8d77096ba2e5
|
|
7
|
+
data.tar.gz: 6df549b39d2ba998aff3899eb27729a988d428d76ad7c14789f5c0a1e64b920a1eb6f7f6a0051beb24754baf3825413fe2dad08519f6ffb02d7097af4255cb3b
|
|
@@ -5,7 +5,7 @@ require "json"
|
|
|
5
5
|
module LocoStrings
|
|
6
6
|
# The XCStringsDecoder class is responsible for decoding the XCStrings file format.
|
|
7
7
|
class XCStringsDecoder
|
|
8
|
-
attr_reader :language, :strings, :translations, :languages
|
|
8
|
+
attr_reader :language, :strings, :translations, :languages, :extraction_states
|
|
9
9
|
|
|
10
10
|
def initialize(file_path)
|
|
11
11
|
@file_path = file_path
|
|
@@ -13,6 +13,7 @@ module LocoStrings
|
|
|
13
13
|
@translations = {}
|
|
14
14
|
@languages = []
|
|
15
15
|
@language = nil
|
|
16
|
+
@extraction_states = {}
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def decode
|
|
@@ -44,6 +45,7 @@ module LocoStrings
|
|
|
44
45
|
strings = json["strings"]
|
|
45
46
|
strings.each do |key, value|
|
|
46
47
|
translatable = value.fetch("shouldTranslate", true)
|
|
48
|
+
@extraction_states[key] = value["extractionState"] if value.key?("extractionState")
|
|
47
49
|
val = decode_string(key, value, @language)
|
|
48
50
|
@strings[key] = val if val
|
|
49
51
|
@strings[key] = LocoString.new(key, key, value["comment"], "new") if val.nil?
|
|
@@ -7,11 +7,12 @@ module LocoStrings
|
|
|
7
7
|
class XCStringsEncoder
|
|
8
8
|
attr_reader :language, :strings, :translations, :languages
|
|
9
9
|
|
|
10
|
-
def initialize(strings, translations, languages, language)
|
|
10
|
+
def initialize(strings, translations, languages, language, extraction_states = {})
|
|
11
11
|
@strings = strings
|
|
12
12
|
@translations = translations
|
|
13
13
|
@languages = languages
|
|
14
14
|
@language = language
|
|
15
|
+
@extraction_states = extraction_states || {}
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
def encode
|
|
@@ -43,7 +44,15 @@ module LocoStrings
|
|
|
43
44
|
sorted_keys.each do |language|
|
|
44
45
|
process_language(row, language, key)
|
|
45
46
|
end
|
|
46
|
-
|
|
47
|
+
state = @extraction_states[key]
|
|
48
|
+
return row if state.nil?
|
|
49
|
+
|
|
50
|
+
# Keep Xcode's alphabetical field order: comment, extractionState, localizations, shouldTranslate.
|
|
51
|
+
ordered = {}
|
|
52
|
+
ordered["comment"] = row.delete("comment") if row.key?("comment")
|
|
53
|
+
ordered["extractionState"] = state
|
|
54
|
+
ordered.merge!(row)
|
|
55
|
+
ordered
|
|
47
56
|
end
|
|
48
57
|
|
|
49
58
|
def sorted_keys
|
|
@@ -19,13 +19,14 @@ module LocoStrings
|
|
|
19
19
|
@strings = decoder.strings
|
|
20
20
|
@translations = decoder.translations
|
|
21
21
|
@languages = decoder.languages
|
|
22
|
+
@extraction_states = decoder.extraction_states
|
|
22
23
|
@strings
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def write
|
|
26
27
|
raise Error, "The base language is not defined" if @language.nil?
|
|
27
28
|
|
|
28
|
-
json = XCStringsEncoder.new(@strings, @translations, @languages, @language).encode
|
|
29
|
+
json = XCStringsEncoder.new(@strings, @translations, @languages, @language, @extraction_states || {}).encode
|
|
29
30
|
File.write(@file_path, json)
|
|
30
31
|
end
|
|
31
32
|
|
|
@@ -99,6 +100,7 @@ module LocoStrings
|
|
|
99
100
|
@translations = {}
|
|
100
101
|
@languages = []
|
|
101
102
|
@language = nil
|
|
103
|
+
@extraction_states = {}
|
|
102
104
|
end
|
|
103
105
|
|
|
104
106
|
private
|
data/lib/loco_strings/version.rb
CHANGED
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.6
|
|
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: 2026-06-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: nokogiri
|
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
84
84
|
- !ruby/object:Gem::Version
|
|
85
85
|
version: '0'
|
|
86
86
|
requirements: []
|
|
87
|
-
rubygems_version: 3.
|
|
87
|
+
rubygems_version: 3.5.22
|
|
88
88
|
signing_key:
|
|
89
89
|
specification_version: 4
|
|
90
90
|
summary: LocoStrings is a Ruby gem for working with iOS and Android localization strings.
|