loco_tool 0.1.1 → 0.1.3
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 -0
- data/bin/locotool +17 -0
- data/lib/helper.rb +50 -1
- data/lib/logger.rb +16 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb7acfbf180e88ff2c907df0e3693b81a638b84b5496664405464f6896f6b43e
|
4
|
+
data.tar.gz: b0bcb5897fdb6ae131fa305be90c1ff6c495033c75ae893f098840f65b0b272f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3563ec7bf3d3929600cd78c79877fbe0d1fa93246daf3d0a00787da567e1f5853c283afdc3215df31aa36cb176458b76146e1f8473e19356bd0425bbf65a9aca
|
7
|
+
data.tar.gz: b3e43a621bc994bc16cf8186392def9184dc85918c480c0bfa0fb5446bd52910524ca8e78c981f75da4ff09ca19855170527962ad3a5d3574a723136b21e7769
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# LocoTool
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/loco_tool)
|
4
|
+

|
5
|
+
|
3
6
|
LocoTool is a command-line tool for localization tasks, designed to simplify the management and validation of localization strings in iOS and Android projects.
|
4
7
|
|
5
8
|
## Features
|
@@ -48,6 +51,22 @@ $ locotool sync_ios_auto [PATH_A] [PATH_B] [BASE_LANG]
|
|
48
51
|
|
49
52
|
This command automatically finds and syncs iOS localization files in the specified directories (`PATH_A` and `PATH_B`). It iterates over the available target languages, excluding the base language (`BASE_LANG`), and performs the synchronization operation.
|
50
53
|
|
54
|
+
### Transform Localization Files
|
55
|
+
|
56
|
+
```
|
57
|
+
$ locotool export [PATH_A] [PATH_B] -s [SORT] -c [CASE]
|
58
|
+
```
|
59
|
+
|
60
|
+
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
|
+
|
62
|
+
## Examples
|
63
|
+
|
64
|
+
Export Localization file from iOS to Android
|
65
|
+
|
66
|
+
```sh
|
67
|
+
$ locotool export en.lproj/Localizable.strings en.xml -s asc -c lower
|
68
|
+
```
|
69
|
+
|
51
70
|
## Contributing
|
52
71
|
|
53
72
|
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
@@ -10,6 +10,23 @@ require_relative "../lib/helper"
|
|
10
10
|
#
|
11
11
|
# Usage: locotool [command] [options]
|
12
12
|
class Locotool < Thor
|
13
|
+
desc "export FILE_A FILE_B", "Export keys from FILE_A to FILE_B"
|
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
|
+
def export(file_a, file_b)
|
17
|
+
sorted = Helper.sort(file_a, options[:sort])
|
18
|
+
Logger.header("Exporting #{Paint[sorted.length.to_s, :green]} keys")
|
19
|
+
Helper.transform_keys(sorted, options[:case])
|
20
|
+
|
21
|
+
File.delete(file_b) if File.exist?(file_b)
|
22
|
+
strings_b = LocoStrings.load(file_b)
|
23
|
+
|
24
|
+
sorted.each do |string|
|
25
|
+
strings_b.update(string.key, string.value, string.comment)
|
26
|
+
end
|
27
|
+
strings_b.write
|
28
|
+
end
|
29
|
+
|
13
30
|
desc "dublicates FILE_A FILE_B", "Find duplicate keys in localization files"
|
14
31
|
def dublicates(file_a, file_b)
|
15
32
|
strings_a = LocoStrings.load(file_a).read
|
data/lib/helper.rb
CHANGED
@@ -60,9 +60,58 @@ 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
|
67
67
|
end
|
68
|
+
|
69
|
+
# Sorts the strings in the specified file
|
70
|
+
#
|
71
|
+
# @param file [String] The file to sort
|
72
|
+
# @param sort [String] The sort order (asc or desc)
|
73
|
+
#
|
74
|
+
# @return [Array] An array of sorted strings
|
75
|
+
def self.sort(file, sort)
|
76
|
+
strings = LocoStrings.load(file).read
|
77
|
+
sorted = []
|
78
|
+
strings.each do |key, string|
|
79
|
+
sorted << string
|
80
|
+
end
|
81
|
+
if sort
|
82
|
+
if sort == "asc"
|
83
|
+
sorted.sort! { |a, b| a.key <=> b.key }
|
84
|
+
elsif sort == "desc"
|
85
|
+
sorted.sort! { |a, b| b.key <=> a.key }
|
86
|
+
else
|
87
|
+
Logger.error("Invalid sort option")
|
88
|
+
exit
|
89
|
+
end
|
90
|
+
end
|
91
|
+
return sorted
|
92
|
+
end
|
93
|
+
|
94
|
+
# Transforms the keys in the specified file
|
95
|
+
#
|
96
|
+
# @param file [String] The file to transform
|
97
|
+
# @param transform_type [String] The transform type (lower, upper)
|
98
|
+
#
|
99
|
+
# @return [void]
|
100
|
+
def self.transform_keys(strings, transform_type)
|
101
|
+
if !transform_type
|
102
|
+
return
|
103
|
+
end
|
104
|
+
strings.each do |string|
|
105
|
+
old_key = string.key
|
106
|
+
if transform_type == "lower"
|
107
|
+
string.key = string.key.downcase
|
108
|
+
elsif transform_type == "upper"
|
109
|
+
string.key = string.key.upcase
|
110
|
+
else
|
111
|
+
Logger.error("Invalid transform type")
|
112
|
+
exit
|
113
|
+
end
|
114
|
+
Logger.key_transform(old_key, string)
|
115
|
+
end
|
116
|
+
end
|
68
117
|
end
|
data/lib/logger.rb
CHANGED
@@ -27,6 +27,14 @@ class Logger
|
|
27
27
|
puts "#{Formatter.string(string.key, string.value)} ↔ #{Paint[duplicate.value.to_s, :blue]}"
|
28
28
|
end
|
29
29
|
|
30
|
+
# Prints a key transfom message.
|
31
|
+
#
|
32
|
+
# @param old_key [String] The old key.
|
33
|
+
# @param string [LocoString] The LocoString object with a new key.
|
34
|
+
def self.key_transform(old_key, string)
|
35
|
+
puts "#{Paint[old_key, :red]} → #{Formatter.string(string.key, string.value)}"
|
36
|
+
end
|
37
|
+
|
30
38
|
# Prints a header.
|
31
39
|
#
|
32
40
|
# @param text [String] The text to print as the header.
|
@@ -52,6 +60,13 @@ class Logger
|
|
52
60
|
puts "Lost keys: #{keys.length}"
|
53
61
|
puts keys.map { |key| Paint[key.to_s, :red] }.join(", ")
|
54
62
|
end
|
63
|
+
|
64
|
+
# Prints an error message.
|
65
|
+
#
|
66
|
+
# @param message [String] The error message to print.
|
67
|
+
def self.error(message)
|
68
|
+
puts Paint["Error: #{message}", :red]
|
69
|
+
end
|
55
70
|
end
|
56
71
|
|
57
72
|
# Provides utility methods for formatting strings
|
@@ -63,6 +78,6 @@ class Formatter
|
|
63
78
|
#
|
64
79
|
# @return [String] The formatted key-value pair as a string
|
65
80
|
def self.string(key, value)
|
66
|
-
"#{Paint[key, :green]} #{Paint[value, :blue]}"
|
81
|
+
"#{Paint[key, :green]}: #{Paint[value, :blue]}"
|
67
82
|
end
|
68
83
|
end
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Cherepanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: loco_strings
|