1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-28 14:30:51 +00:00

Dev: Add synchronized block when loading lang [#330]

This commit is contained in:
gnosygnu 2019-02-10 08:33:58 -05:00
parent 571f0a2388
commit e80dfc6adc
23 changed files with 94 additions and 86 deletions

View File

@ -25,8 +25,10 @@ import gplx.xowa.apps.*; import gplx.xowa.files.exts.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.guis.tabs.*;
public class Xoa_app_fxt {
public static Xoae_app Make__app__edit() {
Io_mgr.Instance.InitEngine_mem();
public static Xoae_app Make__app__edit() {return Make__app__edit(true);}
public static Xoae_app Make__app__edit(boolean reset_fsys) {
if (reset_fsys)
Io_mgr.Instance.InitEngine_mem();
Db_conn_bldr.Instance.Reg_default_mem();
return Make__app__edit("linux", Io_url_.mem_dir_("mem/xowa/"));
}

View File

@ -229,11 +229,10 @@ public class Xowe_wiki implements Xow_wiki, Gfo_invk, Gfo_evt_itm {
parser_mgr.Init_by_wiki();
// init ns_mgr
if (lang.Init_by_load()) {
if (domain_tid == Xow_domain_tid_.Tid__wikipedia) // NOTE: if type is wikipedia, add "Wikipedia" as an alias; PAGE:en.w:pt.wikipedia.org/wiki/Página principal which redirects to Wikipedia:Página principal
ns_mgr.Aliases_add(Xow_ns_.Tid__project, Xow_ns_.Alias__wikipedia);
special_mgr.Evt_lang_changed(lang);
}
lang.Init_by_load();
if (domain_tid == Xow_domain_tid_.Tid__wikipedia) // NOTE: if type is wikipedia, add "Wikipedia" as an alias; PAGE:en.w:pt.wikipedia.org/wiki/Página principal which redirects to Wikipedia:Página principal
ns_mgr.Aliases_add(Xow_ns_.Tid__project, Xow_ns_.Alias__wikipedia);
special_mgr.Evt_lang_changed(lang);
app.Gfs_mgr().Run_url_for(this, app.Fsys_mgr().Cfg_wiki_core_dir().GenSubFil(domain_str + ".gfs")); // NOTE: must be run after lang.Init_by_load b/c lang will reload ns_mgr; DATE:2015-04-17run cfg for wiki by user ; EX: /xowa/user/anonymous/wiki/en.wikipedia.org/cfg/user_wiki.gfs
cfg_parser.Xtns().Itm_pages().Init(ns_mgr); // init ns_mgr for Page / Index ns just before rebuild; usually set by #cfg file
Xow_ns_mgr_.rebuild_(lang, ns_mgr); // always rebuild; may be changed by user_wiki.gfs; different lang will change namespaces; EX: de.wikisource.org will have Seite for File and none of {{#lst}} will work

View File

@ -94,7 +94,8 @@ public class Xob_cmd_mgr implements Gfo_invk {
}
private Object Add_many(GfoMsg m) {
Xowe_wiki wiki = Wiki_get_or_make(m);
wiki.Lang().Init_by_load_assert(); // NOTE: must check that lang is loaded; else case_mgr will not initialize; DATE:2013-05-11
// TOMBSTONE: redundant since Wiki_get_or_make also calls Init_by_load(); DATE:2019-02-09
// wiki.Lang().Init_by_load_assert(); // NOTE: must check that lang is loaded; else case_mgr will not initialize; DATE:2013-05-11
int args_len = m.Args_count();
String[] cmds = new String[args_len - 1]; // -1 b/c 1st arg is wiki
for (int i = 1; i < args_len; i++) {

View File

@ -33,21 +33,29 @@ public class Xoa_lang_mgr implements Gfo_invk {
public int Len() {return hash.Count();}
public void Add(Xol_lang_itm itm) {hash.Add(itm.Key_bry(), itm);}
public Io_url Root_dir() {return root_dir;} private final Io_url root_dir;
public Xol_lang_itm Get_at(int i) {return (Xol_lang_itm)hash.Get_at(i);}
public Xol_lang_itm Get_by(byte[] key) {return (Xol_lang_itm)hash.Get_by(key);}
public Xol_lang_itm Get_by_or_load(byte[] key) {return Get_by_or_new(key).Init_by_load_assert();}
public Xol_lang_itm Get_by_or_en(byte[] key) { // called by Xowv_wiki for its .Lang()
Xol_lang_itm rv = Get_by(key);
return rv == null ? lang_en : rv;
public Xol_lang_itm Get_by_or_null(byte[] key) {return (Xol_lang_itm)hash.Get_by(key);} // check if exists
public Xol_lang_itm Get_by_or_load(byte[] key) { // main call
Xol_lang_itm rv = Get_by_or_null(key);
if (rv == null) {
rv = Xol_lang_itm.New(this, key);
rv.Init_by_load();
this.Add(rv);
}
return rv;
}
public Xol_lang_itm Get_by_or_new(byte[] key) {
Xol_lang_itm rv = Get_by(key);
public Xol_lang_itm Get_by_or_new(byte[] key) { // largely deprecated; should only be used for builders
Xol_lang_itm rv = Get_by_or_null(key);
if (rv == null) {
rv = Xol_lang_itm.New(this, key);
this.Add(rv);
}
return rv;
}
public Xol_lang_itm Get_at(int i) {return (Xol_lang_itm)hash.Get_at(i);} // called by Xol_mw_lang_parser
public Xol_lang_itm Get_by_or_en(byte[] key) { // called by Xowv_wiki to set .Lang() for DRD
Xol_lang_itm rv = Get_by_or_null(key);
return rv == null ? lang_en : rv;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get_by_or_new(m.ReadBry("key"));
else if (ctx.Match(k, Invk_mediawiki_converter)) return mw_converter;

View File

@ -21,6 +21,7 @@ import gplx.xowa.apps.gfs.*; import gplx.xowa.apps.fsys.*; import gplx.core.intl
import gplx.xowa.guis.langs.*;
public class Xol_lang_itm implements Gfo_invk {
private boolean loaded = false;
private final Object thread_lock = new Object();
public Xol_lang_itm(Xoa_lang_mgr lang_mgr, byte[] key_bry) {
this.lang_mgr = lang_mgr; this.key_bry = key_bry; this.key_str = String_.new_u8(key_bry);
Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key_or_null(key_bry); if (lang_itm == null) throw Err_.new_wo_type("unknown lang_key", "key", String_.new_u8(key_bry));
@ -32,7 +33,6 @@ public class Xol_lang_itm implements Gfo_invk {
this.specials_mgr = new Xol_specials_mgr(this);
this.case_mgr = Env_.Mode_testing() ? Xol_case_mgr_.A7() : Xol_case_mgr_.U8(); // NOTE: if test load ascii b/c utf8 is large; NOTE: placed here b/c tests do not call load; DATE:2014-07-04
this.num_mgr = Xol_num_mgr_.new_by_lang_id(lang_id);
this.lnki_trail_mgr = new Xol_lnki_trail_mgr(this);
this.vnt_mgr = new Xol_vnt_mgr(this);
this.grammar = Xol_grammar_.new_by_lang_id(lang_id);
this.gender = Xol_gender_.new_by_lang_id(lang_id);
@ -78,7 +78,7 @@ public class Xol_lang_itm implements Gfo_invk {
public Xol_gender Gender() {return gender;} private final Xol_gender gender;
public Xol_plural Plural() {return plural;} private final Xol_plural plural;
public Xol_duration_mgr Duration_mgr() {return duration_mgr;} private final Xol_duration_mgr duration_mgr;
public Xol_lnki_trail_mgr Lnki_trail_mgr() {return lnki_trail_mgr;} private final Xol_lnki_trail_mgr lnki_trail_mgr;
public Xol_lnki_trail_mgr Lnki_trail_mgr() {return lnki_trail_mgr;} private final Xol_lnki_trail_mgr lnki_trail_mgr = new Xol_lnki_trail_mgr();
public Xop_lnki_arg_parser Lnki_arg_parser() {return lnki_arg_parser;} private Xop_lnki_arg_parser lnki_arg_parser = new Xop_lnki_arg_parser();
public Xol_func_regy Func_regy() {return func_regy;} private final Xol_func_regy func_regy;
public int Img_thumb_halign_default() {return img_thumb_halign_default;} private int img_thumb_halign_default = Xop_lnki_align_h_.Right;
@ -119,18 +119,20 @@ public class Xol_lang_itm implements Gfo_invk {
;
private static final Hash_adp_bry fallback_dupes_regy = Hash_adp_bry.cs(); // to prevent cyclical loops during loading
public Xol_lang_itm Init_by_load_assert() {if (!loaded) Init_by_load(); return this;}
public boolean Init_by_load() {
if (this.loaded) return false;
fallback_dupes_regy.Clear();
this.loaded = true;
boolean lang_is_en = lang_id == Xol_lang_stub_.Id_en;
if (!lang_is_en) Xol_lang_itm_.Lang_init(this);
msg_mgr.Itm_by_key_or_new(Bry_.new_a7("Lang")).Atrs_set(key_bry, false, false); // set "Lang" keyword; EX: for "fr", "{{int:Lang}}" -> "fr"
Load_lang(key_bry);
ns_aliases.Ary_add_(Xow_ns_canonical_.Ary); // NOTE: always add English canonical as aliases to all languages
this.Evt_lang_changed();
return true;
public Xol_lang_itm Init_by_load() {
synchronized (thread_lock) { // Scribunto can create langs outside of wiki_lang; EX:dewiki and multiple scripts call isRTL for fr; ISSUE#:330; DATE:2019-02-09
if (!loaded) {
this.loaded = true;
fallback_dupes_regy.Clear();
boolean lang_is_en = lang_id == Xol_lang_stub_.Id_en;
if (!lang_is_en) Xol_lang_itm_.Lang_init(this);
msg_mgr.Itm_by_key_or_new(Bry_.new_a7("Lang")).Atrs_set(key_bry, false, false); // set "Lang" keyword; EX: for "fr", "{{int:Lang}}" -> "fr"
Load_lang(key_bry);
ns_aliases.Ary_add_(Xow_ns_canonical_.Ary); // NOTE: always add English canonical as aliases to all languages
this.Evt_lang_changed();
}
}
return this;
}
private void Exec_fallback_load(byte[] fallback_lang) {
Fallback_bry_(fallback_lang);

View File

@ -45,7 +45,7 @@ public class Xobc_utl_make_lang_kwds implements Gfo_invk, Xol_lang_transform {
int hash_len = hash.Count();
for (int i = 0; i < hash_len; i++) {
Xobcl_kwd_lang cfg_lang = (Xobcl_kwd_lang)hash.Get_at(i);
Xol_lang_itm lang = lang_mgr.Get_by(cfg_lang.Key_bry()); if (lang == null) continue;
Xol_lang_itm lang = lang_mgr.Get_by_or_null(cfg_lang.Key_bry()); if (lang == null) continue;
int cfg_grp_len = cfg_lang.Grps().length;
for (int j = 0; j < cfg_grp_len; j++) {
Xobcl_kwd_row cfg_grp = cfg_lang.Grps()[j];

View File

@ -75,7 +75,7 @@ public class Xol_mw_lang_parser {
String lang_key = String_.Replace(String_.Lower(String_.Mid(url.NameOnly(), 8)), "_", "-"); // 8=Messages.length; lower b/c format is MessagesEn.php (need "en")
// if (String_.In(lang_key, "qqq", "enrtl", "bbc", "bbc-latn")) continue;
String text = Io_mgr.Instance.LoadFilStr(url);
Xol_lang_itm lang = lang_mgr.Get_by_or_new(Bry_.new_u8(lang_key));
Xol_lang_itm lang = lang_mgr.Get_by_or_new(Bry_.new_u8(lang_key)); // NOTE: cannot be Get_by_or_load else will load from XO; actual definitions will be loaded from MW below
this.Parse_core(text, lang, bfr, lang_transform);
} catch (Exception exc) {Err_.Noop(exc); Console_adp__sys.Instance.Write_str_w_nl("failed to parse " + url.NameOnly() + Err_.Message_gplx_log(exc));}
}

View File

@ -16,7 +16,6 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx.xowa.langs.lnki_trails; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
public class Xol_lnki_trail_mgr implements Gfo_invk {
public Xol_lnki_trail_mgr(Xol_lang_itm lang) {}
public void Clear() {trie.Clear();}
public int Count() {return trie.Count();}
public Btrie_slim_mgr Trie() {return trie;} private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();

View File

@ -17,22 +17,17 @@ package gplx.xowa.langs.lnki_trails; import gplx.*; import gplx.xowa.*; import g
import org.junit.*;
import gplx.xowa.langs.names.*;
public class Xol_lnki_trail_mgr_tst {
@Before public void init() {fxt.Clear();} private Xol_lnki_trail_mgr_fxt fxt = new Xol_lnki_trail_mgr_fxt();
private final Xol_lnki_trail_mgr_fxt fxt = new Xol_lnki_trail_mgr_fxt();
@Test public void Add_bulk() {
fxt.Test_add_bulk("äöüß", "ä", "ö", "ü", "ß");
}
}
class Xol_lnki_trail_mgr_fxt {
Xol_lang_itm lang; Xol_lnki_trail_mgr lnki_trail_mgr;
public void Clear() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
lang = Xol_lang_itm.New(app.Lang_mgr(), Bry_.new_a7("fr"));
lnki_trail_mgr = lang.Lnki_trail_mgr();
}
private final Xol_lnki_trail_mgr lnki_trail_mgr = new Xol_lnki_trail_mgr();
public void Test_add_bulk(String raw, String... expd_ary) {
lnki_trail_mgr.Add_bulk(Bry_.new_u8(raw));
int expd_len = expd_ary.length;
Tfds.Eq(expd_len, lang.Lnki_trail_mgr().Count());
Tfds.Eq(expd_len, lnki_trail_mgr.Count());
for (int i = 0; i < expd_len; i++) {
byte[] expd_bry = Bry_.new_u8(expd_ary[i]);
byte[] actl_bry = (byte[])lnki_trail_mgr.Trie().Match_bgn(expd_bry, 0, expd_bry.length);

View File

@ -148,7 +148,7 @@ public class Xol_msg_mgr_ {
Xoa_lang_mgr lang_mgr = wiki.App().Lang_mgr();
for (int i = 0; i < fallback_ary_len; i++) {
byte[] fallback = fallback_ary[i];
Xol_lang_itm fallback_lang = lang_mgr.Get_by(fallback);
Xol_lang_itm fallback_lang = lang_mgr.Get_by_or_null(fallback);
if (fallback_lang == null) continue; // NOTE: en has fallback of "false"; ignore bad fallbacks;
rv = fallback_lang.Msg_mgr().Itm_by_key_or_null(msg_key_sub_root);
if (rv != null) break;

View File

@ -165,8 +165,7 @@ public class Xol_lang_srl_tst {
@Test public void Fallback_circular() { // PURPOSE: pt and pt-br cite each other as fallback in Messages*.php; DATE:2013-02-18
Io_mgr.Instance.SaveFilStr(Xol_lang_itm_.xo_lang_fil_(fxt.App().Fsys_mgr(), "pt") , "fallback_load('pt-br');");
Io_mgr.Instance.SaveFilStr(Xol_lang_itm_.xo_lang_fil_(fxt.App().Fsys_mgr(), "pt-br") , "fallback_load('pt');");
Xol_lang_itm lang = Xol_lang_itm.New(fxt.App().Lang_mgr(), Bry_.new_a7("pt"));
lang.Init_by_load();
fxt.App().Lang_mgr().Get_by_or_load(Bry_.new_a7("pt")); // fails if test-suite gets stuck
}
@Test public void Num_fmt() {
String raw = String_.Concat_lines_nl
@ -203,7 +202,7 @@ class Xol_lang_srl_fxt {
app = Xoa_app_fxt.Make__app__edit();
lang = Xol_lang_itm.New(app.Lang_mgr(), Bry_.new_a7("fr"));
Xoa_gfs_mgr.Msg_parser_init(); // required by fallback_load
} GfsCtx ctx = GfsCtx.new_(); Xoa_gfs_bldr bldr = new Xoa_gfs_bldr(); //Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
} GfsCtx ctx = GfsCtx.new_(); Xoa_gfs_bldr bldr = new Xoa_gfs_bldr();
public Xoae_app App() {return app;} private Xoae_app app;
public Xol_lang_itm Lang() {return lang;} private Xol_lang_itm lang;
public Xow_ns ns_(int id, String s) {return new Xow_ns(id, Xow_ns_case_.Tid__1st, Bry_.new_u8(s), false);}

View File

@ -20,8 +20,7 @@ import gplx.xowa.wikis.domains.*;
class Xou_user_ {
public static Xowe_wiki new_or_create_(Xoue_user user, Xoae_app app) {
Io_url wiki_dir = app.Fsys_mgr().Home_wiki_dir();
Xol_lang_itm lang = app.Lang_mgr().Get_by_or_new(Xol_lang_itm_.Key_en);
lang.Init_by_load(); // NOTE: lang.Load() must occur before Xowe_wiki.new() b/c wiki will create parsers based on lang
Xol_lang_itm lang = app.Lang_mgr().Get_by_or_load(Xol_lang_itm_.Key_en); // NOTE: lang.Load() must occur before Xowe_wiki.new() b/c wiki will create parsers based on lang
Xowe_wiki rv = new Xowe_wiki(app, lang, ns_home_(lang.Case_mgr()), Xow_domain_uid_.To_domain(Xow_domain_uid_.Tid_xowa), wiki_dir);
app.Wiki_mgr().Add(rv);
rv.Sys_cfg().Xowa_cmd_enabled_(true);

View File

@ -34,7 +34,11 @@ public class Xoue_user implements Xou_user, Gfo_evt_mgr_owner, Gfo_invk {
public Xow_wiki Wikii() {return this.Wiki();}
public int Gender() {return Xol_gender_.Tid_unknown;}
public Xoae_app Appe() {return app;} private final Xoae_app app;
public Xol_lang_itm Lang() {if (lang == null) {lang = app.Lang_mgr().Get_by_or_new(app.Sys_cfg().Lang()); lang.Init_by_load();} return lang;} private Xol_lang_itm lang;
public Xol_lang_itm Lang() {
if (lang == null)
lang = app.Lang_mgr().Get_by_or_load(app.Sys_cfg().Lang());
return lang;
} private Xol_lang_itm lang;
public void Lang_(Xol_lang_itm v) {
lang = v;
this.Msg_mgr().Lang_(v);

View File

@ -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);
}
}

View File

@ -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

View File

@ -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);
}

View File

@ -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);

View File

@ -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 {

View File

@ -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());
}

View File

@ -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)

View File

@ -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();
}

View File

@ -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;
}

View File

@ -117,7 +117,7 @@ class XomwLanguageFxt {
private final XomwLanguage lang;
public XomwLanguageFxt() {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xol_lang_itm xoLang = Xol_lang_itm.New(app.Lang_mgr(), Bry_.new_a7("en"));
Xol_lang_itm xoLang = app.Lang_mgr().Get_by_or_load(Bry_.new_a7("en"));
this.lang = new XomwLanguage(xoLang);
}
public void Init_digitGroupingPattern(String digitGroupingPattern) {