loco_tool 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 +4 -4
- data/README.md +11 -0
- data/bin/locotool +19 -2
- 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: 1146ef7af84b83e69fb35703d8aca54c75307f72bac634e0fb24de0f2096263d
|
4
|
+
data.tar.gz: 2c7e25f0184813b5405ec9c49e7a6df014654677c1ab6d9480c153be22d7fa7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7e94d5a7cfcca72a7c54b1f30ca9be2b4d80f5d882792645b22970a308d63ceea6aeb5c565ba99ddc893a089bc7e980c3fb28444667dc7c5c2104e1c5788387
|
7
|
+
data.tar.gz: 3c9ee9310a20358454765523a738d3044028af0af1f6a6c1aa52d640a49e30d8981e87ad2fddcfb87e777a66c5cfdd4d22396724a8a6c5ecab1a1b9f3c02e875
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# LocoTool
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/loco_tool.svg)](https://badge.fury.io/rb/loco_tool)
|
4
|
+
![License](https://img.shields.io/badge/license-MIT-blue.svg)
|
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,14 @@ $ 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 transform [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
|
+
|
51
62
|
## Contributing
|
52
63
|
|
53
64
|
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
@@ -3,13 +3,30 @@
|
|
3
3
|
|
4
4
|
require "thor"
|
5
5
|
require "loco_strings"
|
6
|
-
|
7
|
-
|
6
|
+
require_relative "../lib/logger"
|
7
|
+
require_relative "../lib/helper"
|
8
8
|
|
9
9
|
# The Locotool class represents a CLI tool for localization tasks.
|
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
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative '../lib/logger'
|
4
4
|
|
5
5
|
# The Helper class provides utility methods for various tasks.
|
6
6
|
class Helper
|
@@ -65,4 +65,53 @@ class Helper
|
|
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.2
|
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-06-
|
11
|
+
date: 2023-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: loco_strings
|