|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
/*
|
|
|
|
|
XOWA: the XOWA Offline Wiki Application
|
|
|
|
|
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
|
|
|
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
|
|
|
|
|
|
|
|
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
|
|
|
|
or alternatively under the terms of the Apache License Version 2.0.
|
|
|
|
@ -13,11 +13,20 @@ The terms of each license can be found in the source code repository:
|
|
|
|
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
|
|
|
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
|
|
|
|
*/
|
|
|
|
|
package gplx.xowa.xtns.jsonConfigs.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.jsonConfigs.*;
|
|
|
|
|
import org.junit.*; import gplx.core.tests.*;
|
|
|
|
|
import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.libs.*;
|
|
|
|
|
import gplx.xowa.langs.*; import gplx.xowa.langs.names.*;
|
|
|
|
|
import gplx.langs.jsons.*;
|
|
|
|
|
package gplx.xowa.xtns.jsonConfigs.scribunto;
|
|
|
|
|
|
|
|
|
|
import gplx.Bry_;
|
|
|
|
|
import gplx.Keyval;
|
|
|
|
|
import gplx.Keyval_;
|
|
|
|
|
import gplx.String_;
|
|
|
|
|
import gplx.core.tests.Gftest;
|
|
|
|
|
import gplx.langs.jsons.Json_doc;
|
|
|
|
|
import gplx.xowa.Xowe_wiki;
|
|
|
|
|
import gplx.xowa.langs.Xoa_lang_mgr;
|
|
|
|
|
import gplx.xowa.langs.Xol_lang_itm;
|
|
|
|
|
import gplx.xowa.xtns.scribunto.Scrib_invoke_func_fxt;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
public class Jscfg_scrib_lib_tst {
|
|
|
|
|
private final Jscfg_scrib_lib_fxt fxt = new Jscfg_scrib_lib_fxt();
|
|
|
|
|
@Test public void Get() {
|
|
|
|
@ -48,54 +57,9 @@ public class Jscfg_scrib_lib_tst {
|
|
|
|
|
, " 2=Data:Q2"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
@Test public void Get_localize() {
|
|
|
|
|
fxt.Init__page("Data:Test_localize.tab", Json_doc.Make_str_by_apos
|
|
|
|
|
( "{"
|
|
|
|
|
, " 'license': 'CC0-1.0',"
|
|
|
|
|
, " 'description': {"
|
|
|
|
|
, " 'de': 'Objekttabelle',"
|
|
|
|
|
, " 'en': 'Object table'"
|
|
|
|
|
, " },"
|
|
|
|
|
, " 'sources': 'Objects in Data:Data.tab completed by [https://www.wikidata.org Wikidata]',"
|
|
|
|
|
, " 'schema': {"
|
|
|
|
|
, " 'fields': ["
|
|
|
|
|
, " {"
|
|
|
|
|
, " 'name': 'wikidataID',"
|
|
|
|
|
, " 'type': 'String',"
|
|
|
|
|
, " 'title': {"
|
|
|
|
|
, " 'de': 'Wikidata-Item',"
|
|
|
|
|
, " 'en': 'Wikidata item'"
|
|
|
|
|
, " }"
|
|
|
|
|
, " },"
|
|
|
|
|
, " {"
|
|
|
|
|
, " 'name': 'wikidataLabel',"
|
|
|
|
|
, " 'type': 'localized',"
|
|
|
|
|
, " 'title': {"
|
|
|
|
|
, " 'de': 'Wikidata-Label',"
|
|
|
|
|
, " 'en': 'Wikidata label'"
|
|
|
|
|
, " }"
|
|
|
|
|
, " }"
|
|
|
|
|
, " ]"
|
|
|
|
|
, " },"
|
|
|
|
|
, " 'data': ["
|
|
|
|
|
, " ["
|
|
|
|
|
, " 'Q183',"
|
|
|
|
|
, " {"
|
|
|
|
|
, " 'de': 'Deutschland',"
|
|
|
|
|
, " 'en': 'Germany'"
|
|
|
|
|
, " }"
|
|
|
|
|
, " ],"
|
|
|
|
|
, " ["
|
|
|
|
|
, " 'Q61912',"
|
|
|
|
|
, " {"
|
|
|
|
|
, " 'de': 'Wertheim',"
|
|
|
|
|
, " 'en': 'Wertheim am Main'"
|
|
|
|
|
, " }"
|
|
|
|
|
, " ]"
|
|
|
|
|
, " ]"
|
|
|
|
|
, "}"
|
|
|
|
|
));
|
|
|
|
|
fxt.Test__get( "Test_localize.tab", String_.Concat_lines_nl_skip_last
|
|
|
|
|
@Test public void Get_localize_null() { // null defaults to wiki.Lang
|
|
|
|
|
fxt.Init__page__multilingual();
|
|
|
|
|
fxt.Test__get( "Test_localize.tab", null, String_.Concat_lines_nl_skip_last
|
|
|
|
|
( "1="
|
|
|
|
|
, " license=CC0-1.0"
|
|
|
|
|
, " description=Object table"
|
|
|
|
@ -119,6 +83,69 @@ public class Jscfg_scrib_lib_tst {
|
|
|
|
|
, " 2=Wertheim am Main"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
@Test public void Get_localize_underscore() {// underscore retrieves the entire document
|
|
|
|
|
fxt.Init__page__multilingual();
|
|
|
|
|
fxt.Test__get( "Test_localize.tab", "_", String_.Concat_lines_nl_skip_last
|
|
|
|
|
( "1="
|
|
|
|
|
, " license=CC0-1.0"
|
|
|
|
|
, " description="
|
|
|
|
|
, " de=Objekttabelle"
|
|
|
|
|
, " en=Object table"
|
|
|
|
|
, " sources=Objects in Data:Data.tab completed by [https://www.wikidata.org Wikidata]"
|
|
|
|
|
, " schema="
|
|
|
|
|
, " fields="
|
|
|
|
|
, " 1="
|
|
|
|
|
, " name=wikidataID"
|
|
|
|
|
, " type=String"
|
|
|
|
|
, " title="
|
|
|
|
|
, " de=Wikidata-Item"
|
|
|
|
|
, " en=Wikidata item"
|
|
|
|
|
, " 2="
|
|
|
|
|
, " name=wikidataLabel"
|
|
|
|
|
, " type=localized"
|
|
|
|
|
, " title="
|
|
|
|
|
, " de=Wikidata-Label"
|
|
|
|
|
, " en=Wikidata label"
|
|
|
|
|
, " data="
|
|
|
|
|
, " 1="
|
|
|
|
|
, " 1=Q183"
|
|
|
|
|
, " 2="
|
|
|
|
|
, " de=Deutschland"
|
|
|
|
|
, " en=Germany"
|
|
|
|
|
, " 2="
|
|
|
|
|
, " 1=Q61912"
|
|
|
|
|
, " 2="
|
|
|
|
|
, " de=Wertheim"
|
|
|
|
|
, " en=Wertheim am Main"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
@Test public void Get_localize_de() {
|
|
|
|
|
fxt.Init__lang("de", "en");
|
|
|
|
|
fxt.Init__page__multilingual();
|
|
|
|
|
fxt.Test__get( "Test_localize.tab", "de", String_.Concat_lines_nl_skip_last
|
|
|
|
|
( "1="
|
|
|
|
|
, " license=CC0-1.0"
|
|
|
|
|
, " description=Objekttabelle"
|
|
|
|
|
, " sources=Objects in Data:Data.tab completed by [https://www.wikidata.org Wikidata]"
|
|
|
|
|
, " schema="
|
|
|
|
|
, " fields="
|
|
|
|
|
, " 1="
|
|
|
|
|
, " name=wikidataID"
|
|
|
|
|
, " type=String"
|
|
|
|
|
, " title=Wikidata-Item"
|
|
|
|
|
, " 2="
|
|
|
|
|
, " name=wikidataLabel"
|
|
|
|
|
, " type=localized"
|
|
|
|
|
, " title=Wikidata-Label"
|
|
|
|
|
, " data="
|
|
|
|
|
, " 1="
|
|
|
|
|
, " 1=Q183"
|
|
|
|
|
, " 2=Deutschland"
|
|
|
|
|
, " 2="
|
|
|
|
|
, " 1=Q61912"
|
|
|
|
|
, " 2=Wertheim"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
@Test public void pickLocalizedString() {
|
|
|
|
|
Xol_lang_itm lang = fxt.Init__lang("zh-cn", "zh1,zh0");
|
|
|
|
|
|
|
|
|
@ -149,9 +176,61 @@ class Jscfg_scrib_lib_fxt {
|
|
|
|
|
public void Init__page(String page, String text) {
|
|
|
|
|
fxt.Parser_fxt().Init_page_create(commons_wiki, page, text);
|
|
|
|
|
}
|
|
|
|
|
public void Init__page__multilingual() {
|
|
|
|
|
this.Init__page("Data:Test_localize.tab", Json_doc.Make_str_by_apos
|
|
|
|
|
( "{"
|
|
|
|
|
, " 'license': 'CC0-1.0',"
|
|
|
|
|
, " 'description': {"
|
|
|
|
|
, " 'de': 'Objekttabelle',"
|
|
|
|
|
, " 'en': 'Object table'"
|
|
|
|
|
, " },"
|
|
|
|
|
, " 'sources': 'Objects in Data:Data.tab completed by [https://www.wikidata.org Wikidata]',"
|
|
|
|
|
, " 'schema': {"
|
|
|
|
|
, " 'fields': ["
|
|
|
|
|
, " {"
|
|
|
|
|
, " 'name': 'wikidataID',"
|
|
|
|
|
, " 'type': 'String',"
|
|
|
|
|
, " 'title': {"
|
|
|
|
|
, " 'de': 'Wikidata-Item',"
|
|
|
|
|
, " 'en': 'Wikidata item'"
|
|
|
|
|
, " }"
|
|
|
|
|
, " },"
|
|
|
|
|
, " {"
|
|
|
|
|
, " 'name': 'wikidataLabel',"
|
|
|
|
|
, " 'type': 'localized',"
|
|
|
|
|
, " 'title': {"
|
|
|
|
|
, " 'de': 'Wikidata-Label',"
|
|
|
|
|
, " 'en': 'Wikidata label'"
|
|
|
|
|
, " }"
|
|
|
|
|
, " }"
|
|
|
|
|
, " ]"
|
|
|
|
|
, " },"
|
|
|
|
|
, " 'data': ["
|
|
|
|
|
, " ["
|
|
|
|
|
, " 'Q183',"
|
|
|
|
|
, " {"
|
|
|
|
|
, " 'de': 'Deutschland',"
|
|
|
|
|
, " 'en': 'Germany'"
|
|
|
|
|
, " }"
|
|
|
|
|
, " ],"
|
|
|
|
|
, " ["
|
|
|
|
|
, " 'Q61912',"
|
|
|
|
|
, " {"
|
|
|
|
|
, " 'de': 'Wertheim',"
|
|
|
|
|
, " 'en': 'Wertheim am Main'"
|
|
|
|
|
, " }"
|
|
|
|
|
, " ]"
|
|
|
|
|
, " ]"
|
|
|
|
|
, "}"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
public Xol_lang_itm Init__lang(String key, String fallbacks) {
|
|
|
|
|
Xol_lang_itm lang = Xol_lang_itm.New(fxt.Core().App().Lang_mgr(), Bry_.new_u8(key));
|
|
|
|
|
Xoa_lang_mgr lang_mgr = fxt.Core().App().Lang_mgr();
|
|
|
|
|
|
|
|
|
|
Xol_lang_itm lang = Xol_lang_itm.New(lang_mgr, Bry_.new_u8(key));
|
|
|
|
|
lang.Fallback_bry_(Bry_.new_a7(fallbacks));
|
|
|
|
|
lang_mgr.Add(lang);
|
|
|
|
|
|
|
|
|
|
return lang;
|
|
|
|
|
}
|
|
|
|
|
public Keyval[] Init__picklocalizedStringKvs(String... vals) {
|
|
|
|
@ -164,7 +243,10 @@ class Jscfg_scrib_lib_fxt {
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
public void Test__get(String page, String expd) {
|
|
|
|
|
fxt.Test_scrib_proc_str_ary(lib, Jscfg_scrib_lib.Invk_get, Keyval_.Ary(Keyval_.int_(1, page)), expd);
|
|
|
|
|
Test__get(page, null, expd);
|
|
|
|
|
}
|
|
|
|
|
public void Test__get(String page, String lang, String expd) {
|
|
|
|
|
fxt.Test_scrib_proc_str_ary(lib, Jscfg_scrib_lib.Invk_get, Keyval_.Ary(Keyval_.int_(1, page), Keyval_.int_(2, lang)), expd);
|
|
|
|
|
}
|
|
|
|
|
public void Test__pickLocalizedString(Xol_lang_itm lang, Keyval[] kv_ary, String expd) {
|
|
|
|
|
Keyval actl_kv = Jscfg_localizer.pickLocalizedString(lang, "key", kv_ary);
|
|
|
|
|