mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
DownloadCentral: Cleanup filter_by_lang
This commit is contained in:
@@ -73,6 +73,25 @@ public class Xow_domain_itm_ {
|
||||
return new_other(raw);
|
||||
}
|
||||
}
|
||||
public static boolean Match_lang(Xow_domain_itm domain, String match) {
|
||||
// exit early if "*"
|
||||
if (String_.Eq(match, Lang_key__all)) return true;
|
||||
|
||||
// get lang
|
||||
String cur = String_.new_u8(domain.Lang_actl_key());
|
||||
|
||||
// return true if direct match; EX: "en" <-> "en"; "de" <-> "de"
|
||||
if (String_.Eq(cur, match)) return true;
|
||||
|
||||
// handle special cases
|
||||
if (String_.Eq(match, "en"))
|
||||
return String_.In(domain.Domain_str(), "simple.wikipedia.org", "species.wikimedia.org", "www.wikidata.org", "commons.wikimedia.org");
|
||||
else if (String_.Eq(match, "zh"))
|
||||
return String_.Eq(cur, "lzh");
|
||||
return false;
|
||||
}
|
||||
public static final String Lang_key__all = "*";
|
||||
|
||||
private static Xow_domain_itm new_other(byte[] raw) {return Xow_domain_itm.new_(raw, Xow_domain_tid_.Tid__other, Xol_lang_stub_.Key__unknown);}
|
||||
private static byte[] Get_lang_code_for_mw_messages_file(byte[] v) {
|
||||
Object o = alt_domain__lang_by_subdomain.Get_by_bry(v);
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xow_domain_itm_tst {
|
||||
private final Xow_domain_fxt fxt = new Xow_domain_fxt();
|
||||
@Test public void Parse_en_wikipedia() {fxt.Test_parse("en.wikipedia.org" , "en" , "en" , Xow_domain_tid_.Tid__wikipedia);}
|
||||
@@ -31,6 +31,11 @@ public class Xow_domain_itm_tst {
|
||||
@Test public void Parse_ua_wikimedia_org() {fxt.Test_parse("ua.wikimedia.org" , "ua" , "uk" , Xow_domain_tid_.Tid__wikimedia);}
|
||||
@Test public void Parse_ar_wikimedia_org() {fxt.Test_parse("ar.wikimedia.org" , "ar" , "es" , Xow_domain_tid_.Tid__wikimedia);}
|
||||
@Test public void Parse_blank() {fxt.Test_parse("" , "" , "" , Xow_domain_tid_.Tid__other);}
|
||||
@Test public void Match_lang() {
|
||||
fxt.Test__match_lang_y("en", "en.wikipedia.org", "en.wiktionary.org", "simple.wikipedia.org", "species.wikimedia.org", "www.wikidata.org", "commons.wikimedia.org");
|
||||
fxt.Test__match_lang_y("fr", "fr.wikipedia.org", "fr.wiktionary.org");
|
||||
fxt.Test__match_lang_y("zh", "zh-classical.wikipedia.org");
|
||||
}
|
||||
}
|
||||
class Xow_domain_fxt {
|
||||
public void Test_parse(String domain, String expd_orig_lang, String expd_actl_lang, int expd_tid) {
|
||||
@@ -39,4 +44,12 @@ class Xow_domain_fxt {
|
||||
Tfds.Eq_str(expd_actl_lang, String_.new_a7((actl.Lang_actl_key())));
|
||||
Tfds.Eq_int(expd_tid, actl.Domain_type_id());
|
||||
}
|
||||
public void Test__match_lang_y(String lang_code, String... domains) {Test__match_lang(Bool_.Y, lang_code, domains);}
|
||||
public void Test__match_lang(boolean expd, String lang_key_str, String[] domains) {
|
||||
int len = domains.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_domain_itm domain = Xow_domain_itm_.parse(Bry_.new_u8(domains[i]));
|
||||
Gftest.Eq__bool(expd, Xow_domain_itm_.Match_lang(domain, lang_key_str), lang_key_str + "|" + domains[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user