mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
TemplateStyles: Handle empty files
This commit is contained in:
@@ -19,7 +19,6 @@ public class Cldr_name_converter_tst {
|
||||
private final Cldr_name_converter_fxt fxt = new Cldr_name_converter_fxt();
|
||||
@Test public void Extract_key_or_fail() {
|
||||
fxt.Test__Extract_key_or_fail("CldrNamesEn.php" , "En");
|
||||
fxt.Test__Extract_key_or_fail("CldrNamesEn.php" , "en");
|
||||
fxt.Test__Extract_key_or_fail("CldrNameEn.php" , null);
|
||||
fxt.Test__Extract_key_or_fail("CldrNamesEn.txt" , null);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Cldr_name_loader {
|
||||
this.cldr_dir = cldr_dir;
|
||||
}
|
||||
|
||||
public Cldr_name_file Load(String lang_key) {
|
||||
public Cldr_name_file Load_or_null(String lang_key) {
|
||||
// normalize to lc; scrib will pass lower_case, but underlying files are Title_case
|
||||
lang_key = String_.Lower(lang_key);
|
||||
|
||||
@@ -39,12 +39,16 @@ public class Cldr_name_loader {
|
||||
urls_hash = Make_urls_hash(Io_mgr.Instance.QueryDir_fils(cldr_dir));
|
||||
|
||||
// get file
|
||||
Io_url url = (Io_url)urls_hash.Get_by_or_fail(lang_key);
|
||||
byte[] json = Io_mgr.Instance.LoadFilBry(url);
|
||||
if (json == null) {
|
||||
Io_url url = (Io_url)urls_hash.Get_by(lang_key);
|
||||
if (url == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "no cldrName file exists for lang; lang=~{lang}", lang_key);
|
||||
return null;
|
||||
}
|
||||
byte[] json = Io_mgr.Instance.LoadFilBry(url);
|
||||
if (Bry_.Len_eq_0(json)) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "json is empty; lang=~{lang}", lang_key);
|
||||
return null;
|
||||
}
|
||||
|
||||
// parse, cache and return
|
||||
file = Parse(lang_key, json);
|
||||
|
||||
@@ -31,7 +31,7 @@ class Cldr_name_loader_fxt {
|
||||
Io_mgr.Instance.SaveFilStr(Io_url_.new_fil_(Dir_name + fil_name), txt);
|
||||
}
|
||||
public void Test__load_file_is_null(boolean expd, String lang_key) {
|
||||
Cldr_name_file name_file = name_loader.Load(lang_key);
|
||||
Cldr_name_file name_file = name_loader.Load_or_null(lang_key);
|
||||
Gftest.Eq__bool(expd, name_file == null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user