1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Template_styles: Add support for template styles

This commit is contained in:
gnosygnu
2018-10-12 23:16:31 -04:00
parent e78382a8ac
commit a8f6fd0fb0
50 changed files with 1219 additions and 113 deletions

View File

@@ -15,20 +15,24 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.langs; import gplx.*; import gplx.xowa.*;
import gplx.xowa.apps.fsys.*; import gplx.xowa.apps.gfs.*;
import gplx.xowa.langs.bldrs.*;
import gplx.xowa.langs.bldrs.*; import gplx.xowa.langs.names.*;
public class Xoa_lang_mgr implements Gfo_invk {
private final Ordered_hash hash = Ordered_hash_.New_bry();
private final Xobc_utl_make_lang mw_converter;
public Xoa_lang_mgr(Xoa_app app, Xoa_gfs_mgr gfs_mgr) {
private final Xobc_utl_make_lang mw_converter;
public Xoa_lang_mgr(Xoa_app app, Xol_name_mgr name_mgr, Xoa_gfs_mgr gfs_mgr) {
this.root_dir = app.Fsys_mgr().Root_dir();
this.mw_converter = new Xobc_utl_make_lang(this, app.Fsys_mgr(), app.Tid_is_edit() ? ((Xoae_app)app).Msg_log() : null);
this.lang_en = Xol_lang_itm_.Lang_en_make(this); this.Add(lang_en);
this.name_mgr = name_mgr;
this.gfs_mgr = gfs_mgr;
}
public Xoa_gfs_mgr Gfs_mgr() {return gfs_mgr;} private final Xoa_gfs_mgr gfs_mgr;
public Xol_lang_itm Lang_en() {return lang_en;} private final Xol_lang_itm lang_en;
public Xol_name_mgr Name_mgr() {return name_mgr;} private final Xol_name_mgr name_mgr;
public void Clear() {hash.Clear();}
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();}
@@ -39,7 +43,7 @@ public class Xoa_lang_mgr implements Gfo_invk {
public Xol_lang_itm Get_by_or_new(byte[] key) {
Xol_lang_itm rv = Get_by(key);
if (rv == null) {
rv = new Xol_lang_itm(this, key);
rv = Xol_lang_itm.New(this, key);
this.Add(rv);
}
return rv;

View File

@@ -172,4 +172,7 @@ public class Xol_lang_itm implements Gfo_invk {
return rv;
}
private static final byte[][] Fallback_bry_ary__en = new byte[][] {Xol_lang_itm_.Key_en};
public static Xol_lang_itm New(Xoa_lang_mgr lang_mgr, byte[] key_bry) {
return new Xol_lang_itm(lang_mgr, key_bry);
}
}

View File

@@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.langs; import gplx.*; import gplx.xowa.*;
import gplx.core.intls.*; import gplx.xowa.xtns.cites.*; import gplx.xowa.xtns.gallery.*;
import gplx.xowa.langs.bldrs.*; import gplx.xowa.langs.numbers.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.langs.bldrs.*; import gplx.xowa.langs.numbers.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.langs.names.*;
import gplx.xowa.apps.fsys.*;
public class Xol_lang_itm_ {
public static Io_url xo_lang_fil_(Xoa_fsys_mgr app_fsys_mgr, String lang_key) {return app_fsys_mgr.Cfg_lang_core_dir().GenSubFil(lang_key + ".gfs");}
@@ -45,7 +45,7 @@ public class Xol_lang_itm_ {
}
public static final byte[] Key_en = Bry_.new_a7("en");
public static Xol_lang_itm Lang_en_make(Xoa_lang_mgr lang_mgr) {
Xol_lang_itm rv = new Xol_lang_itm(lang_mgr, Xol_lang_itm_.Key_en);
Xol_lang_itm rv = Xol_lang_itm.New(lang_mgr, Xol_lang_itm_.Key_en);
Xol_lang_itm_.Lang_init(rv);
rv.Evt_lang_changed();
return rv;

View File

@@ -15,6 +15,7 @@ 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 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();
@Test public void Add_bulk() {
@@ -25,7 +26,7 @@ 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 = new Xol_lang_itm(app.Lang_mgr(), Bry_.new_a7("fr"));
lang = Xol_lang_itm.New(app.Lang_mgr(), Bry_.new_a7("fr"));
lnki_trail_mgr = lang.Lnki_trail_mgr();
}
public void Test_add_bulk(String raw, String... expd_ary) {

View File

@@ -0,0 +1,60 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
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.langs.names; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.btries.*;
import gplx.core.intls.*;
class Strcpn {
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs();
public Strcpn(byte[][] ary) {
for (byte[] val : ary) {
trie.Add_bry(val);
}
}
public int Exec(byte[] val) {
int val_len = val.length;
Btrie_rv trv = new Btrie_rv();
int pos_in_chars = 0;
int pos_in_bytes = 0;
while (pos_in_bytes < val_len) {
byte b = val[pos_in_bytes];
trie.Match_at_w_b0(trv, b, val, pos_in_bytes, val_len);
// no match; try next pos_in_bytes
if (trv.Pos() == pos_in_bytes) {
pos_in_bytes += Utf8_.Len_of_char_by_1st_byte(b);
pos_in_chars++;
}
// match; return pos_in_bytes
else {
return pos_in_chars;
}
}
return pos_in_chars;
}
public static byte[][] Split_concatenated_ascii(String str) {
byte[] bry = Bry_.new_u8(str);
int len = bry.length;
byte[][] rv = new byte[len][];
for (int i = 0; i < len; i++) {
rv[i] = new byte[] {bry[i]};
}
return rv;
}
public static Strcpn New_by_concatenated_ascii(String s) {
return new Strcpn(Split_concatenated_ascii(s));
}
}

View File

@@ -0,0 +1,55 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
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.langs.names; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import org.junit.*;
import gplx.core.tests.*;
public class Strcpn_tst {
private final Strcpn_fxt fxt = new Strcpn_fxt();
@Test public void Single() {
fxt.Test__exec(0, "a" , "a__");
fxt.Test__exec(1, "a" , "_a_");
fxt.Test__exec(2, "a" , "__a");
fxt.Test__exec(3, "a" , "___");
}
@Test public void Multiple() {
fxt.Test__exec(2, "ab" , "__a");
fxt.Test__exec(2, "ab" , "__b");
fxt.Test__exec(1, "ab" , "_ba");
fxt.Test__exec(3, "ab" , "___");
}
@Test public void Utf8() {
fxt.Test__exec(3, "d" , "ab¢d"); // len=2
fxt.Test__exec(3, "d" , "ab€d"); // len=3
fxt.Test__exec(4, "z" , "ab€d"); // len=3
}
@Test public void Php_doc() { // REF: http://php.net/manual/en/function.strcspn.php
fxt.Test__exec_rev(0, "abcd" , "apple");
fxt.Test__exec_rev(0, "abcd" , "banana");
fxt.Test__exec_rev(2, "hello" , "l");
fxt.Test__exec_rev(2, "hello" , "world");
fxt.Test__exec_rev(5, "hello" , "na");
// fxt.Test__exec(0, "abcdhelloabcd" , "l" , -9);
// fxt.Test__exec(0, "abcdhelloabcd" , "l" , -9, -5);
}
}
class Strcpn_fxt {
public void Test__exec_rev(int expd, String subject, String mask) {Test__exec(expd, mask, subject);}
public void Test__exec(int expd, String mask, String subject) {
Strcpn mgr = Strcpn.New_by_concatenated_ascii(mask);
Gftest.Eq__int(expd, mgr.Exec(Bry_.new_u8(subject)));
}
}

View File

@@ -0,0 +1,52 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
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.langs.names; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
/**
* Allowed title characters -- regex character class
* Don't change this unless you know what you're doing
*
* Problematic punctuation:
* - []{}|# Are needed for link syntax, never enable these
* - <> Causes problems with HTML escaping, don't use
* - % Enabled by default, minor problems with path to query rewrite rules, see below
* - + Enabled by default, but doesn't work with path to query rewrite rules,
* corrupted by apache
* - ? Enabled by default, but doesn't work with path to PATH_INFO rewrites
*
* All three of these punctuation problems can be avoided by using an alias,
* instead of a rewrite rule of either variety.
*
* The problem with % is that when using a path to query rewrite rule, URLs are
* double-unescaped: once by Apache's path conversion code, and again by PHP. So
* %253F, for example, becomes "?". Our code does not double-escape to compensate
* for this, indeed double escaping would break if the double-escaped title was
* passed in the query String rather than the path. This is a minor security issue
* because articles can be created such that they are hard to view or edit.
*
* In some rare cases you may wish to remove + for compatibility with old links.
*
* Theoretically 0x80-0x9F of ISO 8859-1 should be disallowed, but
* this breaks interlanguage links
*/
// REF.MW: /includes/DefaultSettings.php
class Title_chars_regx {
public boolean Matches(byte[] bry) {
return false;
}
}
// $wgLegalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+"; /*
// */

View File

@@ -0,0 +1,246 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
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.langs.names; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.core.primitives.*;
import gplx.xowa.xtns.cldrs.*;
public class Xol_name_mgr {
private final Cldr_name_loader cldr_loader;
private final Language_name_loader name_loader;
private final Io_url root_dir;
// private Ordered_hash hash;
// private Keyval[] kvs;
public Xol_name_mgr(Cldr_name_loader cldr_loader, Language_name_loader name_loader, Io_url root_dir) {
this.cldr_loader = cldr_loader;
this.name_loader = name_loader;
this.root_dir = root_dir;
}
/**
* @param String $code The code of the language for which to get the name
* @param null|String $inLanguage Code of language in which to return the name (null for autonyms)
* @param String $include 'all', 'mw' or 'mwfile'; see fetchLanguageNames()
* @return String Language name or empty
* @since 1.20
*/
public String fetchLanguageName(String code, byte[] inLanguage, byte[] include_bry) {
code = String_.Lower(code);
if (include_bry == null) include_bry = fetchLanguageNamesUncached__all__key;
Ordered_hash array = fetchLanguageNames(inLanguage, include_bry);
Keyval rv = (Keyval)array.Get_by(code);
return rv == null ? "" : rv.Val_to_str_or_null();
}
/**
* Get an array of language names, indexed by code.
* @param null|String $inLanguage Code of language in which to return the names
* Use null for autonyms (native names)
* @param String $include One of:
* 'all' all available languages
* 'mw' only if the language is defined in MediaWiki or wgExtraLanguageNames (default)
* 'mwfile' only if the language is in 'mw' *and* has a message file
* @return array Language code => language name
* @since 1.20
*/
// = 'mw
private Ordered_hash languageNameCache;
private Ordered_hash lang_names_cached;
private Ordered_hash lang_files_cached;
private static final byte[] Null_bry = Bry_.new_a7("null");
public Ordered_hash fetchLanguageNames(byte[] inLanguage, byte[] include_bry) {
byte[] cacheKey = inLanguage == null ? Null_bry : inLanguage;
cacheKey = Bry_.Add(cacheKey, Byte_ascii.Colon_bry, include_bry);
if (languageNameCache == null)
languageNameCache = Ordered_hash_.New_bry();
Ordered_hash ret = (Ordered_hash)languageNameCache.Get_by(cacheKey);
if (ret == null) {
Byte_obj_val include_byte = (Byte_obj_val)fetchLanguageNamesUncachedEnum.Get_by(include_bry);
byte include = include_byte == null ? fetchLanguageNamesUncached__all : include_byte.Val();
Cldr_name_file cldr_file = cldr_loader.Load(String_.new_u8(inLanguage));
if (lang_names_cached == null)
lang_names_cached = name_loader.Load_as_hash();
if (lang_files_cached == null) {
lang_files_cached = Ordered_hash_.New();
Io_url[] urls = Io_mgr.Instance.QueryDir_fils(root_dir.GenSubDir_nest("bin", "any", "xowa", "cfg", "lang", "core"));
for (Io_url url : urls) {
String code = url.NameOnly();
lang_files_cached.Add(code, Keyval_.new_(code, code));
}
}
ret = fetchLanguageNamesUncached(inLanguage, include, cldr_file.Language_names(), lang_names_cached, lang_files_cached);
languageNameCache.Add(cacheKey, ret);
}
return ret;
/*
$ret = self::$languageNameCache->get( $cacheKey );
if ( !$ret ) {
$ret = self::fetchLanguageNamesUncached( $inLanguage, $include );
self::$languageNameCache->set( $cacheKey, $ret );
}
return $ret;
*/
}
// public Keyval Get_by_or_null(String code) {
// if (hash == null) Init();
// return (Keyval)hash.Get_by(code);
// }
// public Keyval[] Get_all() {
// if (hash == null) Init();
// return kvs;
// }
/*
private static final Hash_adp isValidCode_cache = Hash_adp_bry.cs();
private static final Strcpn isValidCode_strcpn = Strcpn.New_by_concatenated_ascii(":/\\\000&<>'\"");
private boolean isValidCode(byte[] code) {
Bool_obj_val rv = (Bool_obj_val)isValidCode_cache.Get_by(code);
if (rv == null) {
// People think language codes are html safe, so enforce it.
// Ideally we should only allow a-zA-Z0-9-
// but, .+ and other chars are often used for {{int:}} hacks
// see bugs T39564, T39587, T38938
rv =
// Protect against path traversal
( isValidCode_strcpn.Exec(code) == code.length
// && !preg_match( MediaWikiTitleCodec::getTitleInvalidRegex(), $code );
)
? Bool_obj_val.True
: Bool_obj_val.False;
isValidCode_cache.Add(code, rv);
}
return rv.Val();
}
*/
// private void Init() {
// Cldr_name_file file = cldr_loader.Load(String_.new_u8(host_lang));
// Ordered_hash cldr_names = file.Language_names();
// Ordered_hash lang_names = name_loader.Load_as_hash();
//
// Ordered_hash lang_files = Ordered_hash_.New();
// Io_url[] urls = Io_mgr.Instance.QueryDir_fils(root_dir.GenSubDir_nest("bin", "any", "xowa", "cfg", "lang", "core"));
// foreach (Io_url url in urls) {
// String code = url.NameOnly();
// lang_files.Add(code, Keyval_.new_(code, code));
// }
//
// hash = fetchLanguageNamesUncached(host_lang, fetchLanguageNamesUncached__mw, cldr_names, lang_names, lang_files);
// kvs = (Keyval[])hash.To_ary(typeof(Keyval));
// }
public static final byte
fetchLanguageNamesUncached__mw = 0 // cldr + Names.php + *.json|*.php
, fetchLanguageNamesUncached__all = 1 // cldr + Names.php
, fetchLanguageNamesUncached__mwFile = 2 // *.json|*.php
;
private static final byte[] fetchLanguageNamesUncached__all__key = Bry_.new_a7("all");
private static final Hash_adp_bry fetchLanguageNamesUncachedEnum = Hash_adp_bry.cs()
.Add_str_byte("mw", fetchLanguageNamesUncached__mw)
.Add_str_byte("all", fetchLanguageNamesUncached__all)
.Add_str_byte("mwFile", fetchLanguageNamesUncached__mwFile)
;
public static Ordered_hash fetchLanguageNamesUncached
( byte[] inLanguage, byte include
, Ordered_hash cldr_names
, Ordered_hash lang_names
, Ordered_hash lang_files
) {
// XOWA: skip this for now
// If passed an invalid language code to use, fallback to en
// if ( $inLanguage !== null && !Language::isValidCode( $inLanguage ) ) {
// $inLanguage = 'en';
Ordered_hash names = Ordered_hash_.New();
// XOWA: 'LanguageGetTranslatedLanguageNames' is only hooked by cldr_names
// if ( $inLanguage ) {
// # TODO: also include when $inLanguage is null, when this code is more efficient
// Hooks::run( 'LanguageGetTranslatedLanguageNames', [ &$names, $inLanguage ] );
// }
int cldr_names_len = cldr_names.Len();
for (int i = 0; i < cldr_names_len; i++) {
Keyval kv = (Keyval)cldr_names.Get_at(i);
names.Add(kv.Key(), kv);
}
// REF.MW: /includes/DefaultSettings.php
// global $wgExtraLanguageNames;
// REF.MW: /languages/data/Names.php
// $mwNames = $wgExtraLanguageNames + MediaWiki\Languages\Data\Names::$names;
Ordered_hash mwNames = lang_names;
int mwNames_len = mwNames.Len();
String inLanguageStr = String_.new_u8(inLanguage);
for (int i = 0; i < mwNames_len; i++) {
Keyval mw_name = (Keyval)mwNames.Get_at(i);
// # - Prefer own MediaWiki native name when not using the hook
// # - For other mwNames just add if not added through the hook
String code = mw_name.Key();
if (String_.Eq(code, inLanguageStr) || !names.Has(code)) {
names.Add_if_dupe_use_nth(code, Keyval_.new_(code, mw_name.Val_to_str_or_empty()));
}
}
if (include == fetchLanguageNamesUncached__all) {
names.Sort_by(Hash_kv_sorter.Instance);
return names;
}
Ordered_hash returnMw = Ordered_hash_.New();
mwNames_len = mwNames.Len();
for (int i = 0; i < mwNames_len; i++) {
Keyval coreName = (Keyval)mwNames.Get_at(i);
String code = coreName.Key();
returnMw.Add(code, (Keyval)names.Get_by(code));
}
// REF.MW: /languages/classes/i18n/*.json
// REF.MW: /languages/classes/messages/Messages*.php
if (include == fetchLanguageNamesUncached__mwFile) {
Ordered_hash namesMwFile = Ordered_hash_.New();
// # We do this using a foreach over the codes instead of a directory
// # loop so that messages files in extensions will work correctly.
int returnMwLen = returnMw.Len();
for (int i = 0; i < returnMwLen; i++) {
Keyval kv = (Keyval)returnMw.Get_at(i);
String code = kv.Key();
if (lang_files.Has(code)) {
namesMwFile.Add(code, (Keyval)names.Get_by(code));
}
}
namesMwFile.Sort_by(Hash_kv_sorter.Instance);
return namesMwFile;
}
returnMw .Sort_by(Hash_kv_sorter.Instance);
// # 'mw' option; default if it's not one of the other two options (all/mwfile)
return returnMw;
}
public static Xol_name_mgr New(Io_url root_dir) {
return new Xol_name_mgr(new Cldr_name_loader(root_dir), new Language_name_loader(root_dir), root_dir);
}
}
class Hash_kv_sorter implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Keyval lhs = (Keyval)lhsObj;
Keyval rhs = (Keyval)rhsObj;
return String_.Compare(lhs.Key(), rhs.Key());
}
public static final Hash_kv_sorter Instance = new Hash_kv_sorter(); Hash_kv_sorter() {}
}

View File

@@ -0,0 +1,115 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 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.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
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.langs.names; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import org.junit.*;
import gplx.core.tests.*;
import gplx.xowa.xtns.cldrs.*;
public class Xol_name_mgr_tst {
private final Xol_name_mgr_fxt fxt = new Xol_name_mgr_fxt();
@Test public void Cldr_only() {
fxt.Test__fetchLanguageNamesUncached
( "en", Xol_name_mgr.fetchLanguageNamesUncached__all
, fxt.Make__cldr_names("en", "de")
, fxt.Make__lang_names()
, fxt.Make__lang_files()
, fxt.Make__expd_langs
( "de|de_cldr"
, "en|en_cldr"
));
}
@Test public void Lang_name__langs() {
fxt.Test__fetchLanguageNamesUncached
( "en", Xol_name_mgr.fetchLanguageNamesUncached__all
, fxt.Make__cldr_names("en", "de", "es")
, fxt.Make__lang_names("en", "de", "fr")
, fxt.Make__lang_files()
, fxt.Make__expd_langs
( "de|de_cldr" // do not use de_lange
, "en|en_lang" // use en_lang b/c of "if (String_.Eq(code, inLanguage)"
, "es|es_cldr" // make sure es_lang is still there
, "fr|fr_lang" // add fr_lang
));
}
@Test public void mwFile() {
fxt.Test__fetchLanguageNamesUncached
( "en", Xol_name_mgr.fetchLanguageNamesUncached__mwFile
, fxt.Make__cldr_names("en", "de")
, fxt.Make__lang_names("en", "de", "fr")
, fxt.Make__lang_files("en", "de", "es")
, fxt.Make__expd_langs
( "de|de_cldr"
, "en|en_lang"
));
}
@Test public void mw() {
fxt.Test__fetchLanguageNamesUncached
( "en", Xol_name_mgr.fetchLanguageNamesUncached__mw
, fxt.Make__cldr_names("en", "de")
, fxt.Make__lang_names("en", "de", "fr")
, fxt.Make__lang_files("en", "de", "es")
, fxt.Make__expd_langs
( "de|de_cldr"
, "en|en_lang"
, "fr|fr_lang"
));
}
}
class Xol_name_mgr_fxt {
public Ordered_hash Make__cldr_names(String... vals) {return Fill(Add_suffix(vals, "_cldr"));}
public Ordered_hash Make__lang_names(String... vals) {return Fill(Add_suffix(vals, "_lang"));}
public Ordered_hash Make__lang_files(String... vals) {return Fill(Add_suffix(vals, "_file"));}
public Ordered_hash Make__expd_langs(String... vals) {return Fill(vals);}
public void Test__fetchLanguageNamesUncached
( String inLanguage, byte include
, Ordered_hash cldr_names
, Ordered_hash lang_names
, Ordered_hash lang_files
, Ordered_hash expd_langs) {
Ordered_hash actl_langs = Xol_name_mgr.fetchLanguageNamesUncached(Bry_.new_u8(inLanguage), include, cldr_names, lang_names, lang_files);
Gftest.Eq__ary(To_str_ary(expd_langs), To_str_ary(actl_langs));
}
private static String[] Add_suffix(String[] ary, String val_suffix) {
int len = ary.length;
for (int i = 0; i < len; i++) {
String itm = ary[i];
ary[i] = itm + "|" + itm + val_suffix;
}
return ary;
}
private static String[] To_str_ary(Ordered_hash hash) {
int len = hash.Len();
String[] rv = new String[len];
for (int i = 0; i < len; i++) {
Keyval kv = (Keyval)hash.Get_at(i);
rv[i] = kv.Key() + "|" + kv.Val();
}
return rv;
}
private static Ordered_hash Fill(String... ary) {
Ordered_hash hash = Ordered_hash_.New();
int len = ary.length;
for (int i = 0; i < len; i++) {
Keyval kv = Split(ary[i]);
hash.Add(kv.Key(), kv);
}
return hash;
}
private static Keyval Split(String str) {
String[] ary = String_.Split(str, "|");
return Keyval_.new_(ary[0], ary.length == 1 ? ary[0] : ary[1]);
}
}

View File

@@ -17,7 +17,7 @@ package gplx.xowa.langs.parsers; import gplx.*; import gplx.xowa.*; import gplx.
import org.junit.*; import gplx.core.strings.*;
import gplx.core.intls.*;
import gplx.xowa.apps.gfs.*;
import gplx.xowa.langs.numbers.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.langs.bldrs.*; import gplx.xowa.langs.specials.*;
import gplx.xowa.langs.numbers.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.langs.bldrs.*; import gplx.xowa.langs.specials.*; import gplx.xowa.langs.names.*;
import gplx.xowa.wikis.nss.*;
public class Xol_lang_srl_tst {
private Xol_lang_srl_fxt fxt = new Xol_lang_srl_fxt();
@@ -165,7 +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 = new Xol_lang_itm(fxt.App().Lang_mgr(), Bry_.new_a7("pt"));
Xol_lang_itm lang = Xol_lang_itm.New(fxt.App().Lang_mgr(), Bry_.new_a7("pt"));
lang.Init_by_load();
}
@Test public void Num_fmt() {
@@ -201,7 +201,7 @@ public class Xol_lang_srl_tst {
class Xol_lang_srl_fxt {
public void Clear() {
app = Xoa_app_fxt.Make__app__edit();
lang = new Xol_lang_itm(app.Lang_mgr(), Bry_.new_a7("fr"));
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);
public Xoae_app App() {return app;} private Xoae_app app;