loco_tool 0.1.2 → 0.1.4
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/README.md +19 -1
- data/bin/locotool +11 -2
- data/lib/helper.rb +27 -10
- data/lib/logger.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da05eb7a6a6e69b0becea3f9ac18b1621a582335e0e21dfbcce64122e1b1ec00
|
4
|
+
data.tar.gz: fc833dbe4c5c8c80da833f66b2bbc4a335e3fb6120d1887a9e2c472d0edfa158
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f798c9e5cc051e06e17991f2fdf77e5be1c19fb44286f2fa7e8595f6c37eafb7fb9530966d81f404c733db016045cc1313872918f9b873dc46e3286f0e477717
|
7
|
+
data.tar.gz: a35c6c3a2b78c4e024b8e3470736918e6939d66f5eeb38cf6664d3af8bf6db1a74148c609282df0e2207798eeb6512fc764d029218c8124f34b22dfe3c3df348
|
data/README.md
CHANGED
@@ -10,6 +10,8 @@ LocoTool is a command-line tool for localization tasks, designed to simplify the
|
|
10
10
|
- Find duplicate keys between localization files.
|
11
11
|
- Sync and move missing strings between files.
|
12
12
|
- Validate and verify localization files.
|
13
|
+
- Transform localization files between different formats.
|
14
|
+
- Identify oversized strings in localization files.
|
13
15
|
|
14
16
|
### TODO
|
15
17
|
|
@@ -54,11 +56,27 @@ This command automatically finds and syncs iOS localization files in the specifi
|
|
54
56
|
### Transform Localization Files
|
55
57
|
|
56
58
|
```
|
57
|
-
$ locotool
|
59
|
+
$ locotool export [PATH_A] [PATH_B] -s [SORT] -c [CASE]
|
58
60
|
```
|
59
61
|
|
60
62
|
This command transforms localization files from `PATH_A` to `PATH_B`. It can sort the keys in the output files (`SORT`) and change the case of the keys (`CASE`). The `SORT` parameter can be set to `asc`, or `desc`. The `CASE` parameter can be set to `lower`, or `upper`. Both parameters are optional.
|
61
63
|
|
64
|
+
### Identify Oversized Strings
|
65
|
+
|
66
|
+
```
|
67
|
+
$ locotool oversize [PATH_A] [TARGET_LANG] [GAP]
|
68
|
+
```
|
69
|
+
|
70
|
+
This command identifies oversized strings in the localization files in the specified directory (`PATH_A`). It compares the length of the strings in the target language (`TARGET_LANG`) with the base language and reports the strings that exceed the specified gap (`GAP`).
|
71
|
+
|
72
|
+
## Examples
|
73
|
+
|
74
|
+
Export Localization file from iOS to Android
|
75
|
+
|
76
|
+
```sh
|
77
|
+
$ locotool export en.lproj/Localizable.strings en.xml -s asc -c lower
|
78
|
+
```
|
79
|
+
|
62
80
|
## Contributing
|
63
81
|
|
64
82
|
Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request on the [LocoTool GitHub repository](https://github.com/ftp27/loco_tool).
|
data/bin/locotool
CHANGED
@@ -11,8 +11,8 @@ require_relative "../lib/helper"
|
|
11
11
|
# Usage: locotool [command] [options]
|
12
12
|
class Locotool < Thor
|
13
13
|
desc "export FILE_A FILE_B", "Export keys from FILE_A to FILE_B"
|
14
|
-
method_option :sort, :
|
15
|
-
method_option :case, :
|
14
|
+
method_option :sort, aliases: "-s", desc: "Sort keys by name. Values: asc, desc"
|
15
|
+
method_option :case, aliases: "-c", desc: "Transform case to type of case. Values: lowercase, upcase"
|
16
16
|
def export(file_a, file_b)
|
17
17
|
sorted = Helper.sort(file_a, options[:sort])
|
18
18
|
Logger.header("Exporting #{Paint[sorted.length.to_s, :green]} keys")
|
@@ -81,6 +81,15 @@ class Locotool < Thor
|
|
81
81
|
Logger.lost_keys(lost_keys)
|
82
82
|
strings_b_file.write
|
83
83
|
end
|
84
|
+
|
85
|
+
desc "oversize FILE TARGET_LANG GAP", "Identify and flag translations exceeding the length of the original language"
|
86
|
+
def oversize(file, target_lang, gap)
|
87
|
+
unless file.end_with?("xcstrings")
|
88
|
+
Logger.error("File format not supported. Only .xcstrings files are supported")
|
89
|
+
return
|
90
|
+
end
|
91
|
+
Helper.oversize(LocoStrings.load(file), target_lang, gap.to_i)
|
92
|
+
end
|
84
93
|
end
|
85
94
|
|
86
95
|
Locotool.start(ARGV)
|
data/lib/helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../lib/logger"
|
4
4
|
|
5
5
|
# The Helper class provides utility methods for various tasks.
|
6
6
|
class Helper
|
@@ -60,7 +60,7 @@ class Helper
|
|
60
60
|
next unless target_key
|
61
61
|
next unless lost_keys.include?(target_key)
|
62
62
|
|
63
|
-
|
63
|
+
_target.update(target_key, source_string.value)
|
64
64
|
lost_keys.delete(target_key)
|
65
65
|
Logger.string_value(target_key, source_string.value)
|
66
66
|
end
|
@@ -75,20 +75,20 @@ class Helper
|
|
75
75
|
def self.sort(file, sort)
|
76
76
|
strings = LocoStrings.load(file).read
|
77
77
|
sorted = []
|
78
|
-
strings.each do |
|
78
|
+
strings.each do |_key, string|
|
79
79
|
sorted << string
|
80
80
|
end
|
81
|
-
if sort
|
81
|
+
if sort
|
82
82
|
if sort == "asc"
|
83
83
|
sorted.sort! { |a, b| a.key <=> b.key }
|
84
84
|
elsif sort == "desc"
|
85
85
|
sorted.sort! { |a, b| b.key <=> a.key }
|
86
|
-
else
|
86
|
+
else
|
87
87
|
Logger.error("Invalid sort option")
|
88
88
|
exit
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
91
|
+
sorted
|
92
92
|
end
|
93
93
|
|
94
94
|
# Transforms the keys in the specified file
|
@@ -98,20 +98,37 @@ class Helper
|
|
98
98
|
#
|
99
99
|
# @return [void]
|
100
100
|
def self.transform_keys(strings, transform_type)
|
101
|
-
|
102
|
-
|
103
|
-
end
|
101
|
+
return unless transform_type
|
102
|
+
|
104
103
|
strings.each do |string|
|
105
104
|
old_key = string.key
|
106
105
|
if transform_type == "lower"
|
107
106
|
string.key = string.key.downcase
|
108
107
|
elsif transform_type == "upper"
|
109
108
|
string.key = string.key.upcase
|
110
|
-
else
|
109
|
+
else
|
111
110
|
Logger.error("Invalid transform type")
|
112
111
|
exit
|
113
112
|
end
|
114
113
|
Logger.key_transform(old_key, string)
|
115
114
|
end
|
116
115
|
end
|
116
|
+
|
117
|
+
# Finds oversize strings in the specified file
|
118
|
+
#
|
119
|
+
# @param file [String] The file to check
|
120
|
+
# @param target_lang [String] The target language
|
121
|
+
# @param gap [Integer] The gap between the source length and target strings
|
122
|
+
#
|
123
|
+
# @return [void]
|
124
|
+
def self.oversize(file, target_lang, gap)
|
125
|
+
strings = file.read
|
126
|
+
strings.each do |key, string|
|
127
|
+
target_string = file.value(key, target_lang)
|
128
|
+
limit_length = string.value.length + gap
|
129
|
+
next unless limit_length < target_string.length
|
130
|
+
|
131
|
+
Logger.oversize(string, target_string)
|
132
|
+
end
|
133
|
+
end
|
117
134
|
end
|
data/lib/logger.rb
CHANGED
@@ -27,6 +27,12 @@ class Logger
|
|
27
27
|
puts "#{Formatter.string(string.key, string.value)} ↔ #{Paint[duplicate.value.to_s, :blue]}"
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.oversize(original, string)
|
31
|
+
length = original.value.length
|
32
|
+
puts "#{Formatter.string(original.key,
|
33
|
+
original.value)} ↔ #{Paint[string[0...length], :blue]}#{Paint[string[length...], :red]}"
|
34
|
+
end
|
35
|
+
|
30
36
|
# Prints a key transfom message.
|
31
37
|
#
|
32
38
|
# @param old_key [String] The old key.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loco_tool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Cherepanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: loco_strings
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
|
-
rubygems_version: 3.4.
|
110
|
+
rubygems_version: 3.4.19
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: A CLI tool for parsing and validating localization strings
|