Language.java
2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Decompiled with CFR 0_118.
*/
package com.day.cq.commons;
import java.util.Locale;
public class Language {
private final Locale locale;
private final String language;
private final String country;
public Language(Locale locale) {
this.locale = locale;
this.language = locale.getLanguage();
this.country = locale.getCountry();
}
public Language(String code) {
code = code.replaceAll("-", "_");
int idx = code.indexOf(95);
if (idx < 0) {
this.language = code;
this.country = "";
this.locale = new Locale(this.language);
} else {
this.language = code.substring(0, idx);
this.country = code.substring(idx + 1);
this.locale = new Locale(this.language, this.country);
}
}
public Language(Locale locale, String language, String country) {
this.locale = locale;
this.language = language;
this.country = country;
}
public Language(String language, String country) {
this.language = language;
this.country = country;
this.locale = new Locale(language, country);
}
public Locale getLocale() {
return this.locale;
}
public String getLanguageCode() {
return this.language;
}
public String getCountryCode() {
return this.country;
}
public String toString() {
StringBuilder sb = new StringBuilder(this.language);
if (this.country.length() > 0) {
sb.append("_").append(this.country);
}
return sb.toString();
}
public static Locale getLocale(String code) {
if (code == null) {
return null;
}
int idx = (code = code.replaceAll("-", "_")).indexOf(95);
if (idx < 0) {
return new Locale(code);
}
String language = code.substring(0, idx);
String country = code.substring(idx + 1);
idx = country.indexOf(95);
if (idx < 0) {
return new Locale(language, country);
}
return new Locale(language, country.substring(0, idx), country.substring(idx + 1));
}
}