Skip to content

Commit 0ac7dcb

Browse files
committed
Add fix to merge chinese locales
1 parent 0a4d96c commit 0ac7dcb

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
.vscode
44
.DS_Store
5+
.idea

src/android_gen.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::{anyhow, Ok, Result};
22
use lazy_static::lazy_static;
33
use regex::{Captures, Match, Regex};
44
use std::{collections::HashMap, io::Write, path::Path};
5-
5+
use std::borrow::Cow;
66
use std::fs;
77

88
use crate::parse::{File, Key, LocalizedString, PluralValue, Section, StringValue};
@@ -50,9 +50,7 @@ impl GenResult {
5050
let lang = LANG_WITH_REGION_RE.replace_all(&locale.value, |caps: &Captures| {
5151
format!("-r{}", caps.get(1).unwrap().as_str())
5252
});
53-
if !locale_code_supported_in_android(&lang) {
54-
continue;
55-
}
53+
let lang = update_special_locales(&lang);
5654

5755
let subpath = dir.as_ref().join(format!("values-{}", lang));
5856
if !subpath.is_dir() {
@@ -92,9 +90,16 @@ impl GenResult {
9290
}
9391
}
9492

95-
fn locale_code_supported_in_android(code: &str) -> bool {
96-
// https://stackoverflow.com/questions/17275697/is-there-any-need-to-prepare-values-zh-and-values-zh-rhk/17276279
97-
return code != "zh-rHans" && code != "zh-rHant" && code != "zh-rPinyin";
93+
// https://stackoverflow.com/questions/17275697/is-there-any-need-to-prepare-values-zh-and-values-zh-rhk/17276279
94+
fn update_special_locales(code: &str) -> String {
95+
return match code {
96+
"zh-rHans" | "zh-rHant" | "zh-rPinyin" => {
97+
"zh-rCN".to_string()
98+
}
99+
&_ => {
100+
code.to_string()
101+
}
102+
};
98103
}
99104

100105
pub fn generate(source: &File) -> Result<GenResult> {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[[Src1]]
2+
[esim_plan]
3+
ru-RU = План eSIM
4+
zh-Hans = eSIM套餐
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<resources>
4+
<string name="esim_plan">План eSIM</string>
5+
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<resources>
4+
<string name="esim_plan">eSIM套餐</string>
5+
</resources>

tests/test.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ fn case_android_13() -> Result<(), Box<dyn Error>> {
6969
basic_test_case("android", "case13", None)
7070
}
7171

72+
#[test]
73+
fn case_android_14() -> Result<(), Box<dyn Error>> {
74+
basic_test_case("android", "case14", None)
75+
}
76+
7277
fn basic_test_case(
7378
platform: &str,
7479
case_rel_path: &str,

0 commit comments

Comments
 (0)