-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating Locale with specified Language script (#250)
* Creating a util function to convert Locale string to Locale, but take language script into consideration * emptz commit to trigger auto build
- Loading branch information
1 parent
bbd714c
commit b8944fb
Showing
5 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/LocaleUtility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package edu.cornell.mannlib.vitro.webapp.utils; | ||
|
||
import org.apache.commons.lang3.LocaleUtils; | ||
|
||
import java.util.Locale; | ||
|
||
public final class LocaleUtility { | ||
|
||
private LocaleUtility(){} | ||
|
||
public static Locale languageStringToLocale(String localeString){ | ||
String[] parsedLoc = localeString.trim().split("_", -1); | ||
//regex pattern for locale tag with script specified | ||
Locale locale = localeString.matches("^[a-z]{1,3}_[A-Z][a-z]{3}_[A-Z]{2}") ? | ||
new Locale.Builder().setLanguage(parsedLoc[0]).setRegion(parsedLoc[2]).setScript(parsedLoc[1]).build() : | ||
LocaleUtils.toLocale(localeString); | ||
return locale; | ||
} | ||
} |