Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

.vscode
.DS_Store
.idea
19 changes: 12 additions & 7 deletions src/android_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{anyhow, Ok, Result};
use lazy_static::lazy_static;
use regex::{Captures, Match, Regex};
use std::{collections::HashMap, io::Write, path::Path};

use std::borrow::Cow;
use std::fs;

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

let subpath = dir.as_ref().join(format!("values-{}", lang));
if !subpath.is_dir() {
Expand Down Expand Up @@ -92,9 +90,16 @@ impl GenResult {
}
}

fn locale_code_supported_in_android(code: &str) -> bool {
// https://stackoverflow.com/questions/17275697/is-there-any-need-to-prepare-values-zh-and-values-zh-rhk/17276279
return code != "zh-rHans" && code != "zh-rHant" && code != "zh-rPinyin";
// https://stackoverflow.com/questions/17275697/is-there-any-need-to-prepare-values-zh-and-values-zh-rhk/17276279
fn update_special_locales(code: &str) -> String {
return match code {
"zh-rHans" | "zh-rHant" | "zh-rPinyin" => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я предупредил, что если они вставят два подряд идущих из этого списка, то они смержатся в одно значение.

"zh-rCN".to_string()
}
&_ => {
code.to_string()
}
};
}

pub fn generate(source: &File) -> Result<GenResult> {
Expand Down
4 changes: 4 additions & 0 deletions tests/cases/android/case14/input/src1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[[Src1]]
[esim_plan]
ru-RU = План eSIM
zh-Hans = eSIM套餐
5 changes: 5 additions & 0 deletions tests/cases/android/case14/output/values-ru-rRU/src1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<string name="esim_plan">План eSIM</string>
</resources>
5 changes: 5 additions & 0 deletions tests/cases/android/case14/output/values-zh-rCN/src1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<string name="esim_plan">eSIM套餐</string>
</resources>
5 changes: 5 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ fn case_android_13() -> Result<(), Box<dyn Error>> {
basic_test_case("android", "case13", None)
}

#[test]
fn case_android_14() -> Result<(), Box<dyn Error>> {
basic_test_case("android", "case14", None)
}

fn basic_test_case(
platform: &str,
case_rel_path: &str,
Expand Down