loco_strings 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/lib/loco_strings/parsers/loco_file.rb +1 -0
- data/lib/loco_strings/parsers/xcstrings_file.rb +69 -0
- data/lib/loco_strings/version.rb +1 -1
- data/lib/loco_strings.rb +7 -2
- data/loco_strings.gemspec +40 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ae94b18e40b03e455e87bd4c5a4a4b2139ee822e0f67fb7bddd4f525027a936
|
4
|
+
data.tar.gz: f4decc1b1751dc3f9cdafdf7db9ac9e950f344e3990c2ed7db9373238e760193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7be956a59f8a41eabf7a7196cd03e0979f411b4f511c43c0c4a607af32b680e85b1e7d210445070786f43024d9eabcfe7b6c504283b93c1ddc1ca2206cd7b36e
|
7
|
+
data.tar.gz: e80e535b831507b88eeb25e9d392ca4f39b91112c73d5f2074f69965cacbb8109d0cf3806694ed9164ce5cee417849e4ed13130885edd5efdab9b9dd6181fd2c
|
data/README.md
CHANGED
@@ -10,6 +10,27 @@ That's where LocoStrings comes in. With LocoStrings, you can easily parse and ma
|
|
10
10
|
|
11
11
|
In this README, we'll show you how to install and use LocoStrings in your Ruby projects. Let's get started!
|
12
12
|
|
13
|
+
### Supported formats
|
14
|
+
|
15
|
+
Here is the list of currently supported files, as well as files that are still on the to-do list. I am still working on the library, and I hope to eventually finish all the files on the list. Contributions are welcome.
|
16
|
+
|
17
|
+
- [x] Android Resources
|
18
|
+
- [x] Apple Strings
|
19
|
+
- [ ] Gettext
|
20
|
+
- [ ] Java Properties
|
21
|
+
- [ ] Apple XLIFF
|
22
|
+
- [ ] Objective-C/Cocoa Properties
|
23
|
+
- [ ] .NET Resources
|
24
|
+
- [ ] JavaScript Object
|
25
|
+
- [ ] React Native (I18n library)
|
26
|
+
- [ ] Symphony PHP XLIFF
|
27
|
+
- [ ] Angular i18n XLIFF
|
28
|
+
- [ ] Ruby YAML
|
29
|
+
- [ ] Salesforce Translation
|
30
|
+
- [ ] QT Linguist
|
31
|
+
- [ ] Docx
|
32
|
+
- [ ] Flutter ARB file
|
33
|
+
|
13
34
|
## Installation
|
14
35
|
|
15
36
|
Install the gem and add to the application's Gemfile by executing:
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require_relative "loco_file"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module LocoStrings
|
5
|
+
class XCStringsFile < LocoFile
|
6
|
+
def initialize(file_path, language)
|
7
|
+
@file_path = file_path
|
8
|
+
@language = language
|
9
|
+
clean
|
10
|
+
end
|
11
|
+
|
12
|
+
def read
|
13
|
+
clean
|
14
|
+
return @strings unless File.exist?(@file_path)
|
15
|
+
|
16
|
+
comment = nil
|
17
|
+
file = File.read(@file_path)
|
18
|
+
json = JSON.parse(file)
|
19
|
+
sourceLanguage = json["sourceLanguage"]
|
20
|
+
strings = json["strings"]
|
21
|
+
strings.each do |key, value|
|
22
|
+
comment = value["comment"]
|
23
|
+
translation = key unless @language != sourceLanguage
|
24
|
+
if value.has_key?("localizations") && value["localizations"].has_key?(@language)
|
25
|
+
loc = value["localizations"][@language]
|
26
|
+
end
|
27
|
+
translation = loc["stringUnit"]["value"] unless loc.nil?
|
28
|
+
@strings[key] = LocoString.new key, translation, comment unless translation.nil?
|
29
|
+
end
|
30
|
+
@strings
|
31
|
+
end
|
32
|
+
|
33
|
+
def write(files = [])
|
34
|
+
json = {}
|
35
|
+
json["sourceLanguage"] = @language
|
36
|
+
json["strings"] = {}
|
37
|
+
@strings.each do |key, value|
|
38
|
+
row = {}
|
39
|
+
row["comment"] = value.comment unless value.comment.nil?
|
40
|
+
localizations = {}
|
41
|
+
if value.value != key && !value.value.nil?
|
42
|
+
localizations[@language] = {
|
43
|
+
"stringUnit" => {
|
44
|
+
"state" => "translated",
|
45
|
+
"value" => value.value
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
files.each do |file|
|
50
|
+
translation = file.value(key)
|
51
|
+
next unless translation
|
52
|
+
|
53
|
+
next unless key != translation
|
54
|
+
|
55
|
+
localizations[file.language] = {
|
56
|
+
"stringUnit" => {
|
57
|
+
"state" => "translated",
|
58
|
+
"value" => translation
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
row["localizations"] = localizations unless localizations.empty?
|
63
|
+
json["strings"][key] = row
|
64
|
+
end
|
65
|
+
json["version"] = "1.0"
|
66
|
+
File.open(@file_path, "w") { |file| file.write(JSON.pretty_generate(json)) }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/loco_strings/version.rb
CHANGED
data/lib/loco_strings.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative "loco_strings/version"
|
4
4
|
require_relative "loco_strings/parsers/android_file"
|
5
5
|
require_relative "loco_strings/parsers/ios_file"
|
6
|
+
require_relative "loco_strings/parsers/xcstrings_file"
|
6
7
|
|
7
8
|
# LocoStrings is a Ruby gem for working with iOS and Android localization strings.
|
8
9
|
module LocoStrings
|
@@ -14,15 +15,19 @@ module LocoStrings
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
def self.load(file_path)
|
18
|
+
def self.load(file_path, language = nil)
|
18
19
|
ext = File.extname(file_path)
|
19
|
-
raise Error, "Unsupported file format: #{ext}" unless [".strings", ".xml"].include? ext
|
20
|
+
raise Error, "Unsupported file format: #{ext}" unless [".strings", ".xml", ".xcstrings"].include? ext
|
20
21
|
|
21
22
|
case ext
|
22
23
|
when ".strings"
|
23
24
|
IosFile.new file_path
|
24
25
|
when ".xml"
|
25
26
|
AndroidFile.new file_path
|
27
|
+
when ".xcstrings"
|
28
|
+
raise Error, "Language is required for xcstrings files" unless language
|
29
|
+
|
30
|
+
XCStringsFile.new file_path, language
|
26
31
|
else
|
27
32
|
raise Error, "Not implemented"
|
28
33
|
end
|
@@ -0,0 +1,40 @@
|
|
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
|
+
end
|
39
|
+
|
40
|
+
# 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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Cherepanov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -56,7 +56,9 @@ files:
|
|
56
56
|
- lib/loco_strings/parsers/android_file.rb
|
57
57
|
- lib/loco_strings/parsers/ios_file.rb
|
58
58
|
- lib/loco_strings/parsers/loco_file.rb
|
59
|
+
- lib/loco_strings/parsers/xcstrings_file.rb
|
59
60
|
- lib/loco_strings/version.rb
|
61
|
+
- loco_strings.gemspec
|
60
62
|
- sig/loco_strings.rbs
|
61
63
|
homepage: https://github.com/ftp27/loco_strings
|
62
64
|
licenses:
|
@@ -79,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
81
|
- !ruby/object:Gem::Version
|
80
82
|
version: '0'
|
81
83
|
requirements: []
|
82
|
-
rubygems_version: 3.4.
|
84
|
+
rubygems_version: 3.4.19
|
83
85
|
signing_key:
|
84
86
|
specification_version: 4
|
85
87
|
summary: LocoStrings is a Ruby gem for working with iOS and Android localization strings.
|