mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Dev: Add synchronized block when loading lang [#330]
This commit is contained in:
@@ -15,40 +15,38 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.pfuncs.langs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*; import gplx.xowa.langs.*;
|
||||
public class Pfunc_i18n_tst {
|
||||
@Before public void init() {fxt.Clear();} private Pfunc_i18n_fxt fxt = new Pfunc_i18n_fxt();
|
||||
@Test public void Casing() {fxt.lang_("de").Ini().Reg_func("fullurl", false, "VOLLSTÄNDIGE_URL").Load().Fxt().Test_parse_tmpl_str_test("{{vollstÄndige_url:a}}", "{{test}}" , "//de.wikipedia.org/wiki/A");}
|
||||
@Test public void Time() {fxt.lang_("de").Ini().Reg_msg("march", "März").Load().Fxt().Test_parse_tmpl_str_test("{{#time: d F Y|1 Mar 2013}}", "{{test}}" , "01 März 2013");}
|
||||
public class Pfunc_i18n_tst {
|
||||
private final Pfunc_i18n_fxt fxt = new Pfunc_i18n_fxt();
|
||||
@Test public void Casing() {
|
||||
fxt.Init__func("de", "fullurl", false, "VOLLSTÄNDIGE_URL");
|
||||
fxt.Init__lang("de");
|
||||
fxt.Test__parse("{{vollstÄndige_url:a}}", "{{test}}" , "//de.wikipedia.org/wiki/A");
|
||||
}
|
||||
@Test public void Time() {
|
||||
fxt.Init__msg("de", "march", "März");
|
||||
fxt.Init__lang("de");
|
||||
fxt.Test__parse("{{#time: d F Y|1 Mar 2013}}", "{{test}}" , "01 März 2013");
|
||||
}
|
||||
}
|
||||
class Pfunc_i18n_fxt {
|
||||
public void Clear() {}
|
||||
public Xop_fxt Fxt() {return fxt;}
|
||||
public Pfunc_i18n_fxt lang_(String v) {lang_key = v; return this;} private String lang_key;
|
||||
public Pfunc_i18n_fxt Ini() {
|
||||
if (app == null) app = Xoa_app_fxt.Make__app__edit();
|
||||
app.Lang_mgr().Clear(); // else lang values retained from last run
|
||||
app.Free_mem(false); // else tmpl_result_cache will get reused from last run for {{test}}
|
||||
lang = app.Lang_mgr().Get_by_or_new(Bry_.new_a7(lang_key));
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app, lang_key + ".wikipedia.org", lang);
|
||||
fxt = new Xop_fxt(app, wiki);
|
||||
return this;
|
||||
} private Xoae_app app; private Xop_fxt fxt; Xol_lang_itm lang; Xowe_wiki wiki;
|
||||
public Pfunc_i18n_fxt Reg_func(String name, boolean case_match, String word) {
|
||||
private Xop_fxt parser_fxt;
|
||||
public void Init__func(String lang_key, String name, boolean case_match, String word) {
|
||||
Io_url url = Io_url_.mem_fil_("mem/xowa/bin/any/xowa/cfg/lang/core/" + lang_key + ".gfs");
|
||||
String func = "keywords.load_text('" + name + "|" + (case_match ? "1" : "0") + "|" + name + "~" + word + "~');";
|
||||
Io_mgr.Instance.SaveFilStr(url, func);
|
||||
return this;
|
||||
}
|
||||
public Pfunc_i18n_fxt Reg_msg(String key, String val) {
|
||||
public void Init__msg(String lang_key, String key, String val) {
|
||||
Io_url url = Io_url_.mem_fil_("mem/xowa/bin/any/xowa/cfg/lang/core/" + lang_key + ".gfs");
|
||||
String func = "messages.load_text('" + key + "|" + val + "');";
|
||||
Io_mgr.Instance.SaveFilStr(url, func);
|
||||
return this;
|
||||
}
|
||||
public Pfunc_i18n_fxt Load() {
|
||||
lang.Init_by_load();
|
||||
wiki.Fragment_mgr().Evt_lang_changed(lang);
|
||||
return this;
|
||||
public void Init__lang(String lang_key) {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit(false);
|
||||
Xol_lang_itm lang = app.Lang_mgr().Get_by_or_load(Bry_.new_a7(lang_key));
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, lang_key + ".wikipedia.org", lang);
|
||||
this.parser_fxt = new Xop_fxt(app, wiki);
|
||||
}
|
||||
public void Test__parse(String tmpl_raw, String page_raw, String expd) {
|
||||
parser_fxt.Test_parse_tmpl_str_test(tmpl_raw, page_raw, expd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -104,8 +104,7 @@ class Pf_msg_mgr_fxt {
|
||||
alt_fxt.Test_parse_tmpl_str_test(raw, "{{test}}" , expd);
|
||||
}
|
||||
public void Test_parse_lang(String other_lang_id, String raw, String expd) {
|
||||
Xol_lang_itm other_lang = fxt.App().Lang_mgr().Get_by_or_new(Bry_.new_a7(other_lang_id));
|
||||
other_lang.Init_by_load();
|
||||
Xol_lang_itm other_lang = fxt.App().Lang_mgr().Get_by_or_load(Bry_.new_a7(other_lang_id));
|
||||
fxt.Page().Lang_(other_lang);
|
||||
fxt.Test_parse_tmpl_str_test(raw, "{{test}}", expd);
|
||||
fxt.Page().Lang_(en_lang); // NOTE: must reset back to en_lang, else rest of tests will look up under fr
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Pf_formatnum_es_tst {
|
||||
private Xop_fxt fxt;
|
||||
@Before public void init() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xol_lang_itm lang = Xol_lang_itm.New(app.Lang_mgr(), Bry_.new_a7("es")).Init_by_load_assert();
|
||||
Xol_lang_itm lang = app.Lang_mgr().Get_by_or_load(Bry_.new_a7("es"));
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "es.wikipedia.org", lang);
|
||||
fxt = new Xop_fxt(app, wiki);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Pf_formatnum_fa_tst {
|
||||
private Xop_fxt fxt;
|
||||
@Before public void init() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xol_lang_itm lang = Xol_lang_itm.New(app.Lang_mgr(), Bry_.new_a7("fa")).Init_by_load_assert();
|
||||
Xol_lang_itm lang = app.Lang_mgr().Get_by_or_load(Bry_.new_a7("fa"));
|
||||
app.Gfs_mgr().Run_str_for(lang, Persian_numbers_gfs);
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "fa.wikipedia.org", lang);
|
||||
fxt = new Xop_fxt(app, wiki);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Pft_func_time extends Pf_func_base {
|
||||
if (Bry_.Len_gt_0(arg_lang)) {
|
||||
Xol_lang_stub specified_lang_itm = Xol_lang_stub_.Get_by_key_or_null(arg_lang);
|
||||
if (specified_lang_itm != null) { // NOTE: if lang_code is bad, then ignore (EX:bad_code)
|
||||
Xol_lang_itm specified_lang = wiki.Appe().Lang_mgr().Get_by_or_new(arg_lang);
|
||||
Xol_lang_itm specified_lang = wiki.Appe().Lang_mgr().Get_by_or_load(arg_lang);
|
||||
lang = specified_lang;
|
||||
}
|
||||
}
|
||||
@@ -59,9 +59,9 @@ public class Pft_func_time extends Pf_func_base {
|
||||
}
|
||||
class DateAdpTranslator_xapp {
|
||||
public static void Translate(Xowe_wiki wiki, Xol_lang_itm lang, int type, int val, Bry_bfr bb) {
|
||||
lang.Init_by_load_assert();
|
||||
byte[] itm_val = lang.Msg_mgr().Val_by_id(type + val); if (itm_val == null) return;
|
||||
bb.Add(itm_val);
|
||||
byte[] itm_val = lang.Msg_mgr().Val_by_id(type + val);
|
||||
if (itm_val != null)
|
||||
bb.Add(itm_val);
|
||||
}
|
||||
}
|
||||
class Pfxtp_roman {
|
||||
|
||||
@@ -153,7 +153,7 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
}
|
||||
public boolean GetFallbacksFor(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] lang_code = args.Pull_bry(0);
|
||||
Xol_lang_itm lang = core.App().Lang_mgr().Get_by(lang_code);
|
||||
Xol_lang_itm lang = core.App().Lang_mgr().Get_by_or_null(lang_code);
|
||||
if (lang == null) return rslt.Init_bry_ary(Bry_.Ary("en")); // lang is not valid; return en; REF:/languages/Language.php|getFallbacksFor; ISSUE#:340; DATE:2019-02-01
|
||||
return rslt.Init_bry_ary(lang.Fallback_bry_ary());
|
||||
}
|
||||
|
||||
@@ -81,8 +81,11 @@ public class Scrib_lib_language_tst {
|
||||
));
|
||||
}
|
||||
@Test public void FormatNum() {
|
||||
Xol_lang_itm other_lang = fxt.Core().App().Lang_mgr().Get_by_or_new(Bry_.new_a7("de")).Init_by_load_assert(); // NOTE: must call Init_by_load_assert, else load will be called by scrib and sprs below will get overwritten during load;
|
||||
// init
|
||||
Xol_lang_itm other_lang = fxt.Core().App().Lang_mgr().Get_by_or_load(Bry_.new_a7("de")); // NOTE: must call load now, else load will be called by scrib and sprs below will get overwritten during load;
|
||||
fxt.Parser_fxt().Init_lang_numbers_separators(other_lang, ".", ",");
|
||||
|
||||
// test
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("de", 1234), "1.234"); // german spr
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", 1234), "1,234"); // english spr
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatNum, Object_.Ary("en", "1234"), "1,234"); // String passed (not int)
|
||||
|
||||
@@ -115,7 +115,7 @@ class Scrib_lib_message_data {
|
||||
if (Bry_.Eq(lang_key, cur_lang) || Bry_.Len_eq_0(lang_key)) // if lang_key == core_lang then use wiki.msg_mgr; also same if lang_key == blank (arg not given)
|
||||
return wiki.Msg_mgr().Val_by_key_args(msg_key, args);
|
||||
else {
|
||||
Xol_lang_itm lang = wiki.Appe().Lang_mgr().Get_by_or_new(lang_key); lang.Init_by_load_assert();
|
||||
Xol_lang_itm lang = wiki.Appe().Lang_mgr().Get_by_or_load(lang_key);
|
||||
Xol_msg_itm msg_itm = lang.Msg_mgr().Itm_by_key_or_null(msg_key); if (msg_itm == null) return Bry_.Empty;
|
||||
return msg_itm.Val();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Wdata_prop_val_visitor implements Wbase_claim_visitor { // THREAD.U
|
||||
public void Init(Bry_bfr bfr, Wdata_hwtr_msgs msgs, byte[] lang_key, boolean mode_is_statements) {
|
||||
// init some member variables;
|
||||
this.bfr = bfr; this.msgs = msgs;
|
||||
this.lang = app.Lang_mgr().Get_by(lang_key);
|
||||
this.lang = app.Lang_mgr().Get_by_or_null(lang_key);
|
||||
if (lang == null) lang = app.Lang_mgr().Lang_en(); // TEST: needed for one test; DATE:2016-10-20
|
||||
this.mode_is_statements = mode_is_statements;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user