Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

Commit 4ec9055

Browse files
authored
Merge pull request #7 from jayrave/update_formatter
Update formatter & pull version number from cargo for release
2 parents af254a2 + 8f609f4 commit 4ec9055

12 files changed

Lines changed: 92 additions & 79 deletions

File tree

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,21 @@ before_deploy:
3333
deploy:
3434
provider: releases
3535
api_key: $GITHUB_TOKEN
36-
file: android_localization-$TRAVIS_TAG-$TARGET.tar.gz
36+
file_glob: true
37+
file: android_localization-*-$TARGET.tar.gz
3738
skip_cleanup: true
3839
draft: true
3940
overwrite: false
4041
on:
4142
branch: master
42-
tags: true
43+
condition: $TRAVIS_TAG = release
4344

4445
branches:
4546
only:
4647
# Pushes and PR to the master & develop branch
4748
- master
48-
- develop
49-
- /^\d+\.\d+\.\d+$/
49+
# To let our `release` tag trigger CI builds
50+
- release
5051

5152
notifications:
5253
email:

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.1.9
2+
- Report each unlocalized string as a separate error
3+
14
# 0.1.8
25
- Make validate fail if there is unlocalized text with an option to turn it off
36

ci/before_deploy.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ cargo build --all --release --target $TARGET --verbose
77
cp target/$TARGET/release/android_localization_cli$EXE_SUFFIX android_localization$EXE_SUFFIX
88

99
# Zip up the executable with name that resembles android_localization-0.1.4-x86_64-unknown-linux-gnu
10-
tar czf android_localization-$TRAVIS_TAG-$TARGET.tar.gz android_localization$EXE_SUFFIX
10+
current_version=`grep "version" cli/Cargo.toml | sed "s/version = //g" | sed "s/'//g"`
11+
echo "using $current_version as version from cli/Cargo.toml"
12+
tar czf android_localization-$current_version-$TARGET.tar.gz android_localization$EXE_SUFFIX

ci/script.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ set -ex
22

33
cargo build --all --target $TARGET --verbose
44
cargo test --all --target $TARGET --verbose
5-
cargo fmt -- --check
6-
cargo clippy -- -D warnings
5+
cargo fmt --all -- --check
6+
cargo clippy --all-targets --all-features -- -D warnings

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = 'android_localization_cli'
3-
version = '0.1.8'
3+
version = '0.1.9'
44
authors = ['jayrave <jayanthan.raveendiran@gmail.com>']
55
edition = '2018'
66

cli/tests/file_utilities/mod.rs

Lines changed: 0 additions & 29 deletions
This file was deleted.

cli/tests/localize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::process::{Command, Output};
22

33
use tempfile::TempDir;
44

5-
mod file_utilities;
5+
use test_utilities;
66

77
#[test]
88
fn succeeds_with_mapping() {
@@ -111,7 +111,7 @@ fn assert_status_and_stdout(output: Output) {
111111
}
112112

113113
fn assert_output_files(temp_dir: TempDir, expected_output_dir_path: &str) {
114-
file_utilities::assert_eq_of_file_contents_to_either_or(
114+
test_utilities::file::assert_eq_of_file_contents_to_either_or(
115115
&format!("{}/to_localize_1.csv", temp_dir.path().to_str().unwrap()),
116116
&format!("{}/es_fr.csv", expected_output_dir_path),
117117
&format!("{}/fr_es.csv", expected_output_dir_path),

cli/tests/localized.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use tempfile::TempDir;
55

66
use test_utilities;
77

8-
mod file_utilities;
9-
108
#[test]
119
fn succeeds_with_mapping() {
1210
execute_with_copied_sample_res(
@@ -70,7 +68,7 @@ fn warns_if_nothing_new_localized() {
7068
"run",
7169
"localized",
7270
"--res-dir",
73-
&output_res_path.clone(),
71+
&output_res_path,
7472
"--input-file",
7573
"./tests_data/localized/warn/input/localized.csv",
7674
])
@@ -194,12 +192,12 @@ fn assert_status_and_stdout(output: Output) {
194192
}
195193

196194
fn assert_output_files(output_res_path: String) {
197-
file_utilities::assert_eq_of_file_contents(
195+
test_utilities::file::assert_eq_of_file_contents(
198196
"./tests_data/localized/success/output/french_strings.xml",
199197
&format!("{}/values-fr/strings.xml", output_res_path),
200198
);
201199

202-
file_utilities::assert_eq_of_file_contents(
200+
test_utilities::file::assert_eq_of_file_contents(
203201
"./tests_data/localized/success/output/spanish_strings.xml",
204202
&format!("{}/values-es/strings.xml", output_res_path),
205203
);

core/src/localized.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ mod tests {
240240

241241
xml_writer::write(&mut zh_strings.file, chinese_android_strings.clone()).unwrap();
242242

243-
fs::create_dir_all(localized_dir_path.clone()).unwrap();
243+
fs::create_dir_all(localized_dir_path).unwrap();
244244
let mut localized_file = File::create(localized_file_path.clone()).unwrap();
245245
localized_file
246246
.write_all(

core/src/validate/formatter.rs

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,33 +92,23 @@ fn format_errors_from_one_file(
9292
}
9393

9494
if let Some(missing_strings) = invalid_strings_file.missing_strings_error {
95-
if !missing_strings.extra_in_default_locale.is_empty() {
95+
for extra in missing_strings.extra_in_default_locale {
9696
issues_count_in_file += 1;
9797
writeln!(
9898
&mut file_output,
99-
"Error {} (unlocalized string(s)): {}",
99+
"Error {} (unlocalized string): {}",
100100
issues_count_in_file,
101-
missing_strings
102-
.extra_in_default_locale
103-
.iter()
104-
.map(|s| s.value())
105-
.collect::<Vec<&str>>()
106-
.join(", ")
101+
extra.value()
107102
)?;
108103
}
109104

110-
if !missing_strings.extra_in_foreign_locale.is_empty() {
105+
for extra in missing_strings.extra_in_foreign_locale {
111106
issues_count_in_file += 1;
112107
writeln!(
113108
&mut file_output,
114-
"Error {} (string(s) not in defaut locale): {}",
109+
"Error {} (string not in defaut locale): {}",
115110
issues_count_in_file,
116-
missing_strings
117-
.extra_in_foreign_locale
118-
.iter()
119-
.map(|s| s.value())
120-
.collect::<Vec<&str>>()
121-
.join(", ")
111+
extra.value()
122112
)?;
123113
}
124114
}
@@ -149,6 +139,8 @@ mod tests {
149139

150140
#[test]
151141
fn formats() {
142+
// These strings needn't be invalid. We can include them in the
143+
// error & the formatter will happily report it
152144
let default_s1 = AndroidString::localizable("s1", "default_value1");
153145
let default_s2 = AndroidString::localizable("s2", "default_value2");
154146
let french_s1 = AndroidString::localizable("s1", "french_value1");
@@ -184,23 +176,38 @@ mod tests {
184176
InvalidStringsFile {
185177
file_path: String::from("spanish"),
186178
apostrophe_error: Some(apostrophe::InvalidStrings {
187-
invalid_strings: vec![spanish_s1.clone()],
179+
invalid_strings: vec![spanish_s1.clone(), spanish_s2.clone()],
188180
}),
189181
format_string_error: Some(format_string::Mismatches {
190-
mismatches: vec![format_string::Mismatch {
191-
default_parsed_data: format_string::ParsedData {
192-
android_string: default_s1.clone(),
193-
sorted_format_strings: vec![String::from("%1$s"), String::from("%1$d")],
182+
mismatches: vec![
183+
format_string::Mismatch {
184+
default_parsed_data: format_string::ParsedData {
185+
android_string: default_s1.clone(),
186+
sorted_format_strings: vec![
187+
String::from("%1$s"),
188+
String::from("%1$d"),
189+
],
190+
},
191+
foreign_parsed_data: format_string::ParsedData {
192+
android_string: spanish_s1.clone(),
193+
sorted_format_strings: vec![String::from("%1$d")],
194+
},
194195
},
195-
foreign_parsed_data: format_string::ParsedData {
196-
android_string: spanish_s1.clone(),
197-
sorted_format_strings: vec![String::from("%1$d")],
196+
format_string::Mismatch {
197+
default_parsed_data: format_string::ParsedData {
198+
android_string: default_s2.clone(),
199+
sorted_format_strings: vec![],
200+
},
201+
foreign_parsed_data: format_string::ParsedData {
202+
android_string: spanish_s2.clone(),
203+
sorted_format_strings: vec![String::from("%1$s")],
204+
},
198205
},
199-
}],
206+
],
200207
}),
201208
missing_strings_error: Some(missing_strings::MissingStrings {
202-
extra_in_default_locale: vec![default_s1.clone(), default_s2.clone()],
203-
extra_in_foreign_locale: vec![spanish_s1.clone(), spanish_s2.clone()],
209+
extra_in_default_locale: vec![default_s1, default_s2],
210+
extra_in_foreign_locale: vec![spanish_s1, spanish_s2],
204211
}),
205212
},
206213
];
@@ -215,14 +222,19 @@ Path: french (1 issue)
215222
Error 1 (mismatched format string(s)): Found [asdf, qwer] in french_value1
216223
Found [] in default_value1
217224
218-
Path: spanish (4 issues)
225+
Path: spanish (8 issues)
219226
Error 1 (unescaped apostrophe): spanish_value1
220-
Error 2 (mismatched format string(s)): Found [%1$d] in spanish_value1
227+
Error 2 (unescaped apostrophe): spanish_value2
228+
Error 3 (mismatched format string(s)): Found [%1$d] in spanish_value1
221229
Found [%1$s, %1$d] in default_value1
222-
Error 3 (unlocalized string(s)): default_value1, default_value2
223-
Error 4 (string(s) not in defaut locale): spanish_value1, spanish_value2
224-
225-
Found 6 issues across 3 files!"#
230+
Error 4 (mismatched format string(s)): Found [%1$s] in spanish_value2
231+
Found [] in default_value2
232+
Error 5 (unlocalized string): default_value1
233+
Error 6 (unlocalized string): default_value2
234+
Error 7 (string not in defaut locale): spanish_value1
235+
Error 8 (string not in defaut locale): spanish_value2
236+
237+
Found 10 issues across 3 files!"#
226238
)
227239
);
228240
}

0 commit comments

Comments
 (0)