loco_tool 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -0
  3. data/bin/locotool +11 -2
  4. data/lib/helper.rb +26 -9
  5. data/lib/logger.rb +6 -0
  6. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb7acfbf180e88ff2c907df0e3693b81a638b84b5496664405464f6896f6b43e
4
- data.tar.gz: b0bcb5897fdb6ae131fa305be90c1ff6c495033c75ae893f098840f65b0b272f
3
+ metadata.gz: da05eb7a6a6e69b0becea3f9ac18b1621a582335e0e21dfbcce64122e1b1ec00
4
+ data.tar.gz: fc833dbe4c5c8c80da833f66b2bbc4a335e3fb6120d1887a9e2c472d0edfa158
5
5
  SHA512:
6
- metadata.gz: 3563ec7bf3d3929600cd78c79877fbe0d1fa93246daf3d0a00787da567e1f5853c283afdc3215df31aa36cb176458b76146e1f8473e19356bd0425bbf65a9aca
7
- data.tar.gz: b3e43a621bc994bc16cf8186392def9184dc85918c480c0bfa0fb5446bd52910524ca8e78c981f75da4ff09ca19855170527962ad3a5d3574a723136b21e7769
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
 
@@ -59,6 +61,14 @@ $ locotool export [PATH_A] [PATH_B] -s [SORT] -c [CASE]
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
+
62
72
  ## Examples
63
73
 
64
74
  Export Localization file from iOS to Android
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, :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"
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 '../lib/logger'
3
+ require_relative "../lib/logger"
4
4
 
5
5
  # The Helper class provides utility methods for various tasks.
6
6
  class Helper
@@ -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 |key, string|
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
- return sorted
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
- if !transform_type
102
- return
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.3
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: 2023-07-03 00:00:00.000000000 Z
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.13
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