loco_strings 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b2e8a8916f1d69b0a109b7a17e68793cbe20eedaa762cc74653f4090048a3cd6
4
+ data.tar.gz: aa5bec6952605aacca4cf1c17a8e07cc10f998cb9192c6671eddbcb944236a0e
5
+ SHA512:
6
+ metadata.gz: 5c2a073409fd64b8a2fc81de277729e73edaccd32889b9e9e63e7fb501d9929dd328451c9c1e6f304e188ac548284282ea26bc0e31154f27c1fa2cb71901b054
7
+ data.tar.gz: 539910989439ece0351c2afc033e53246b945716847884c5b292a0358abd6b191a8f53389de9d39f2d4bb0911d9d97a416474e666ea8516601bd87018db2056f
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ftp27host@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in loco_strings.gemspec
6
+ gemspec
7
+
8
+ gem "nokogiri", "~> 1.14", ">= 1.14.3"
9
+
10
+ gem "rake", "~> 13.0"
11
+
12
+ gem "rspec", "~> 3.0"
13
+
14
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ loco_strings (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ json (2.6.3)
12
+ nokogiri (1.14.3-x86_64-darwin)
13
+ racc (~> 1.4)
14
+ nokogiri (1.14.3-x86_64-linux)
15
+ racc (~> 1.4)
16
+ parallel (1.23.0)
17
+ parser (3.2.2.1)
18
+ ast (~> 2.4.1)
19
+ racc (1.6.2)
20
+ rainbow (3.1.1)
21
+ rake (13.0.6)
22
+ regexp_parser (2.8.0)
23
+ rexml (3.2.5)
24
+ rspec (3.12.0)
25
+ rspec-core (~> 3.12.0)
26
+ rspec-expectations (~> 3.12.0)
27
+ rspec-mocks (~> 3.12.0)
28
+ rspec-core (3.12.2)
29
+ rspec-support (~> 3.12.0)
30
+ rspec-expectations (3.12.3)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.12.0)
33
+ rspec-mocks (3.12.5)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.12.0)
36
+ rspec-support (3.12.0)
37
+ rubocop (1.50.2)
38
+ json (~> 2.3)
39
+ parallel (~> 1.10)
40
+ parser (>= 3.2.0.0)
41
+ rainbow (>= 2.2.2, < 4.0)
42
+ regexp_parser (>= 1.8, < 3.0)
43
+ rexml (>= 3.2.5, < 4.0)
44
+ rubocop-ast (>= 1.28.0, < 2.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (>= 2.4.0, < 3.0)
47
+ rubocop-ast (1.28.0)
48
+ parser (>= 3.2.1.0)
49
+ ruby-progressbar (1.13.0)
50
+ unicode-display_width (2.4.2)
51
+
52
+ PLATFORMS
53
+ x86_64-darwin-22
54
+ x86_64-linux
55
+
56
+ DEPENDENCIES
57
+ loco_strings!
58
+ nokogiri (~> 1.14, >= 1.14.3)
59
+ rake (~> 13.0)
60
+ rspec (~> 3.0)
61
+ rubocop (~> 1.21)
62
+
63
+ BUNDLED WITH
64
+ 2.4.12
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Aleksei Cherepanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # LocoStrings
2
+
3
+ LocoStrings is a Ruby gem that provides utilities for working with localization strings in iOS and Android applications.
4
+
5
+ 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.
6
+
7
+ That's where LocoStrings comes in. With LocoStrings, you can easily parse and manipulate localization strings in both iOS `.strings` and Android `strings.xml` formats, allowing you to automate common localization tasks and ensure the accuracy and consistency of your translations.
8
+
9
+ In this README, we'll show you how to install and use LocoStrings in your Ruby projects. Let's get started!
10
+
11
+ ## Installation
12
+
13
+ Install the gem and add to the application's Gemfile by executing:
14
+
15
+ $ bundle add loco_strings
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ $ gem install loco_strings
20
+
21
+ ## Usage
22
+
23
+ LocoStrings is a Ruby gem that can be used to manage and manipulate strings in iOS and Android applications. It supports two file formats: iOS strings files and Android XML files. The gem provides a simple and intuitive API to read, write, update, and delete strings.
24
+
25
+ To use the gem in your project, you can install it by adding the following line to your Gemfile:
26
+
27
+ ```ruby
28
+ gem 'loco_strings'
29
+ ```
30
+
31
+ Then, run `bundle install` to install the gem.
32
+
33
+ After installing the gem, you can use the `load` method to load a strings file. The method takes one argument, which is the path to the strings file.
34
+
35
+ ```ruby
36
+ strings = LocoStrings.load("path/to/strings/file")
37
+ ```
38
+
39
+ You can then use the `read` method to read the strings from the file. The method returns a hash where the keys are the string keys and the values are instances of the `LocoString` class.
40
+
41
+ ```ruby
42
+ strings_hash = strings.read
43
+ ```
44
+
45
+ You can access the values in the hash using the keys.
46
+
47
+ ```ruby
48
+ value = strings_hash["key"]
49
+ ```
50
+
51
+ You can update a string by using the `update` method. The method takes two or three arguments: the key, the new value, and optionally a new comment.
52
+
53
+ ```ruby
54
+ strings.update("key", "new value", "new comment")
55
+ ```
56
+
57
+ You can delete a string by using the `delete` method. The method takes one argument, which is the key.
58
+
59
+ ```ruby
60
+ strings.delete("key")
61
+ ```
62
+
63
+ You can write the changes back to the file using the `write` method.
64
+
65
+ ```ruby
66
+ strings.write
67
+ ```
68
+
69
+ LocoStrings supports two file formats: iOS strings files and Android XML files. When you load a file, LocoStrings automatically detects the file format and returns an instance of the appropriate class: `IosFile` or `AndroidFile`.
70
+
71
+ Here is an example of how to use LocoStrings to manage an iOS strings file:
72
+
73
+ ```ruby
74
+ strings = LocoStrings.load("path/to/Localizable.strings")
75
+ # Read the strings
76
+ strings_hash = strings.read
77
+ # Update a string
78
+ strings.update("key", "new value")
79
+ # Delete a string
80
+ strings.delete("key")
81
+ # Write the changes back to the file
82
+ strings.write
83
+ ```
84
+
85
+ And here is an example of how to use LocoStrings to manage an Android XML file:
86
+
87
+ ```ruby
88
+ strings = LocoStrings.load("path/to/strings.xml")
89
+ # Read the strings
90
+ strings_hash = strings.read
91
+ # Update a string
92
+ strings.update("key", "new value")
93
+ # Delete a string
94
+ strings.delete("key")
95
+ # Write the changes back to the file
96
+ strings.write
97
+ ```
98
+
99
+ ## Development
100
+
101
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
102
+
103
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
104
+
105
+ ## Contributing
106
+
107
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/ftp27/loco_strings](). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ftp27/loco_strings/blob/master/CODE_OF_CONDUCT.md).
108
+
109
+ ## License
110
+
111
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
112
+
113
+ ## Code of Conduct
114
+
115
+ Everyone interacting in the LocoStrings project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ftp27/loco_strings/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "loco_file"
4
+ require "nokogiri"
5
+
6
+ module LocoStrings
7
+ # AndroidFile is a class for working with Android localization strings.
8
+ class AndroidFile < LocoFile
9
+ def read
10
+ clean
11
+ return @strings unless File.exist?(@file_path)
12
+
13
+ comment = nil
14
+ doc = Nokogiri::XML(File.open(@file_path))
15
+ doc.xpath("//resources").first.children.each do |child|
16
+ comment = extract_comment(child) || comment
17
+ value = extract_string(child, comment)
18
+ comment = nil if value
19
+ end
20
+ @strings
21
+ end
22
+
23
+ def write
24
+ builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
25
+ xml.resources do
26
+ @strings.each do |key, value|
27
+ xml.comment value.comment if value.comment
28
+ xml.string(value.value, name: key)
29
+ end
30
+ end
31
+ end
32
+ File.open(@file_path, "w") { |file| file.write(builder.to_xml) }
33
+ end
34
+
35
+ private
36
+
37
+ def extract_comment(child)
38
+ child.text.strip if child.comment?
39
+ end
40
+
41
+ def extract_string(child, comment)
42
+ return unless child.name == "string"
43
+
44
+ name = child.attr("name")
45
+ value = child.text
46
+ @strings[name] = LocoString.new name, value, comment
47
+ @strings[name]
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "loco_file"
4
+
5
+ module LocoStrings
6
+ # IosFile is a class for working with iOS localization strings.
7
+ class IosFile < LocoFile
8
+ def read
9
+ clean
10
+ return @strings unless File.exist?(@file_path)
11
+
12
+ comment = nil
13
+ file = File.read(@file_path)
14
+ file.split("\n").each do |line|
15
+ comment = extract_comment(line) || comment
16
+ value = extract_string(line, comment)
17
+ comment = nil if value
18
+ end
19
+ @strings
20
+ end
21
+
22
+ def write
23
+ output = ""
24
+ @strings.each do |key, value|
25
+ output += "/* #{value.comment} */\n" if value.comment
26
+ output += "\"#{key}\" = \"#{value.value}\";\n"
27
+ end
28
+ File.open(@file_path, "w") { |file| file.write(output) }
29
+ end
30
+
31
+ private
32
+
33
+ def extract_comment(line)
34
+ comment_match = line.match(%r{^/\*[\s\S]*?(.+)[\s\S]*?\*/$})
35
+ comment_match[1].strip if comment_match
36
+ end
37
+
38
+ def extract_string(line, comment)
39
+ value_match = line.match(/^"(.+)" = "(.+)";$/)
40
+ return unless value_match
41
+
42
+ name = value_match[1]
43
+ value = value_match[2]
44
+ @strings[name] = LocoString.new name, value, comment
45
+ @strings[name]
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LocoStrings
4
+ # LocoFile is a class for working with localization strings.
5
+ class LocoFile
6
+ attr_reader :file_path
7
+
8
+ def initialize(file_path)
9
+ @file_path = file_path
10
+ clean
11
+ end
12
+
13
+ def read
14
+ raise Error, "Not implemented"
15
+ end
16
+
17
+ def write
18
+ raise Error, "Not implemented"
19
+ end
20
+
21
+ def update_file_path(file_path)
22
+ @file_path = file_path
23
+ end
24
+
25
+ def update(key, value, comment = nil)
26
+ @strings[key] = LocoString.new key, value, comment
27
+ end
28
+
29
+ def delete(key)
30
+ @strings.delete key
31
+ end
32
+
33
+ def value(key)
34
+ @strings[key]
35
+ end
36
+
37
+ def clean
38
+ @strings = {}
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LocoStrings
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "loco_strings/version"
4
+ require_relative "loco_strings/parsers/android_file"
5
+ require_relative "loco_strings/parsers/ios_file"
6
+
7
+ # LocoStrings is a Ruby gem for working with iOS and Android localization strings.
8
+ module LocoStrings
9
+ class Error < StandardError; end
10
+
11
+ LocoString = Struct.new(:key, :value, :comment) do
12
+ def initialize(key, value, comment = nil)
13
+ super
14
+ end
15
+ end
16
+
17
+ def self.load(file_path)
18
+ ext = File.extname(file_path)
19
+ raise Error, "Unsupported file format: #{ext}" unless [".strings", ".xml"].include? ext
20
+
21
+ case ext
22
+ when ".strings"
23
+ IosFile.new file_path
24
+ when ".xml"
25
+ AndroidFile.new file_path
26
+ else
27
+ raise Error, "Not implemented"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ module LocoStrings
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loco_strings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aleksei Cherepanov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-05-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: LocoStrings is a powerful and easy-to-use Ruby gem that simplifies the
14
+ process of managing localization strings for iOS and Android apps. With LocoStrings,
15
+ you can easily extract, organize, and update your app's localized strings in one
16
+ place, making it easy to maintain consistency across all of your app's translations.
17
+ LocoStrings supports multiple file formats, including XLIFF and CSV, and provides
18
+ a simple and intuitive API for working with your app's strings in code. Whether
19
+ you're a solo developer or part of a team, LocoStrings makes managing your app's
20
+ localization a breeze.
21
+ email:
22
+ - ftp27host@gmail.com
23
+ executables: []
24
+ extensions: []
25
+ extra_rdoc_files: []
26
+ files:
27
+ - ".rspec"
28
+ - ".rubocop.yml"
29
+ - CODE_OF_CONDUCT.md
30
+ - Gemfile
31
+ - Gemfile.lock
32
+ - LICENSE.txt
33
+ - README.md
34
+ - Rakefile
35
+ - lib/loco_strings.rb
36
+ - lib/loco_strings/parsers/android_file.rb
37
+ - lib/loco_strings/parsers/ios_file.rb
38
+ - lib/loco_strings/parsers/loco_file.rb
39
+ - lib/loco_strings/version.rb
40
+ - sig/loco_strings.rbs
41
+ homepage: https://github.com/ftp27/loco_strings
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ homepage_uri: https://github.com/ftp27/loco_strings
46
+ source_code_uri: https://github.com/ftp27/loco_strings
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.6.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.4.10
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: LocoStrings is a Ruby gem for working with iOS and Android localization strings.
66
+ test_files: []