loco_strings 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2e8a8916f1d69b0a109b7a17e68793cbe20eedaa762cc74653f4090048a3cd6
4
- data.tar.gz: aa5bec6952605aacca4cf1c17a8e07cc10f998cb9192c6671eddbcb944236a0e
3
+ metadata.gz: 4ae94b18e40b03e455e87bd4c5a4a4b2139ee822e0f67fb7bddd4f525027a936
4
+ data.tar.gz: f4decc1b1751dc3f9cdafdf7db9ac9e950f344e3990c2ed7db9373238e760193
5
5
  SHA512:
6
- metadata.gz: 5c2a073409fd64b8a2fc81de277729e73edaccd32889b9e9e63e7fb501d9929dd328451c9c1e6f304e188ac548284282ea26bc0e31154f27c1fa2cb71901b054
7
- data.tar.gz: 539910989439ece0351c2afc033e53246b945716847884c5b292a0358abd6b191a8f53389de9d39f2d4bb0911d9d97a416474e666ea8516601bd87018db2056f
6
+ metadata.gz: 7be956a59f8a41eabf7a7196cd03e0979f411b4f511c43c0c4a607af32b680e85b1e7d210445070786f43024d9eabcfe7b6c504283b93c1ddc1ca2206cd7b36e
7
+ data.tar.gz: e80e535b831507b88eeb25e9d392ca4f39b91112c73d5f2074f69965cacbb8109d0cf3806694ed9164ce5cee417849e4ed13130885edd5efdab9b9dd6181fd2c
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- loco_strings (0.1.0)
4
+ loco_strings (0.1.1)
5
+ nokogiri (~> 1.13, >= 1.13.8)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # LocoStrings
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/loco_strings.svg)](https://badge.fury.io/rb/loco_strings)
4
+
3
5
  LocoStrings is a Ruby gem that provides utilities for working with localization strings in iOS and Android applications.
4
6
 
5
7
  If you're an iOS or Android developer, you know how important it is to properly localize your apps for different languages and regions. However, managing localization files can be a tedious and error-prone task, especially as your app grows and supports more languages.
@@ -8,6 +10,27 @@ That's where LocoStrings comes in. With LocoStrings, you can easily parse and ma
8
10
 
9
11
  In this README, we'll show you how to install and use LocoStrings in your Ruby projects. Let's get started!
10
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
+
11
34
  ## Installation
12
35
 
13
36
  Install the gem and add to the application's Gemfile by executing:
@@ -23,6 +23,7 @@ module LocoStrings
23
23
  end
24
24
 
25
25
  def update(key, value, comment = nil)
26
+ comment = @strings[key].comment if comment.nil? && @strings.has_key?(key)
26
27
  @strings[key] = LocoString.new key, value, comment
27
28
  end
28
29
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LocoStrings
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
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,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loco_strings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
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-05-02 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.13.8
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.13'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.13.8
13
33
  description: LocoStrings is a powerful and easy-to-use Ruby gem that simplifies the
14
34
  process of managing localization strings for iOS and Android apps. With LocoStrings,
15
35
  you can easily extract, organize, and update your app's localized strings in one
@@ -36,7 +56,9 @@ files:
36
56
  - lib/loco_strings/parsers/android_file.rb
37
57
  - lib/loco_strings/parsers/ios_file.rb
38
58
  - lib/loco_strings/parsers/loco_file.rb
59
+ - lib/loco_strings/parsers/xcstrings_file.rb
39
60
  - lib/loco_strings/version.rb
61
+ - loco_strings.gemspec
40
62
  - sig/loco_strings.rbs
41
63
  homepage: https://github.com/ftp27/loco_strings
42
64
  licenses:
@@ -59,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
81
  - !ruby/object:Gem::Version
60
82
  version: '0'
61
83
  requirements: []
62
- rubygems_version: 3.4.10
84
+ rubygems_version: 3.4.19
63
85
  signing_key:
64
86
  specification_version: 4
65
87
  summary: LocoStrings is a Ruby gem for working with iOS and Android localization strings.