public Lang(java.util.Locale locale) { this(new play.api.i18n.Lang(locale)); }
public Lang(play.api.i18n.Lang underlyingLang) { super(underlyingLang.locale()); }
/** * The Lang code (such as fr or en-US). */ public String code() { return underlyingLang.code(); }
/** * Create a Lang value from a code (such as fr or en-US). * * @param code the language code * @return the Lang for the code, or null of no matching lang was found. */ public static Lang forCode(String code) { try { return new Lang(play.api.i18n.Lang.apply(code)); } catch (Exception e) { return null; } }
/** * A valid ISO Country Code. */ public String country() { return underlyingLang.country(); }
/** * Retrieve Lang availables from the application configuration. */ public static List<Lang> availables() { List<play.api.i18n.Lang> langs = Scala.asJava(play.api.i18n.Lang.availables(play.api.Play.current())); List<play.i18n.Lang> result = new ArrayList<play.i18n.Lang>(); for(play.api.i18n.Lang lang: langs) { result.add(new Lang(lang)); } return result; }
private static Result formErrorAsJson(Form<?> formWithErrors) {return badRequest(formWithErrors.errorsAsJson(new Lang(defaultLang())));}
/** * Create a Lang value from a code (such as fr or en-US). */ public static Lang forCode(String code) { try { return new Lang(play.api.i18n.Lang.apply(code)); } catch (Exception e) { return null; } }
public Lang(java.util.Locale locale) { this(new play.api.i18n.Lang(locale)); }
/** * Create a Lang value from a code (such as fr or en-US). * * @param code the language code * @return the Lang for the code, or null of no matching lang was found. */ public static Lang forCode(String code) { try { return new Lang(play.api.i18n.Lang.apply(code)); } catch (Exception e) { return null; } }
public Lang(play.api.i18n.Lang underlyingLang) { super(underlyingLang.locale()); }
public Lang(java.util.Locale locale) { this(new play.api.i18n.Lang(locale)); }
/** * Create a Lang value from a code (such as fr or en-US). * * @param code the language code * @return the Lang for the code, or null of no matching lang was found. */ public static Lang forCode(String code) { try { return new Lang(play.api.i18n.Lang.apply(code)); } catch (Exception e) { return null; } }
public Lang(play.api.i18n.Lang underlyingLang) { super(underlyingLang.locale()); }
private static Lang getLang(){ Lang lang = null; if(play.mvc.Http.Context.current.get() != null) { lang = play.mvc.Http.Context.current().lang(); } else { Locale defaultLocale = Locale.getDefault(); lang = new Lang(new play.api.i18n.Lang(defaultLocale.getLanguage(), defaultLocale.getCountry())); } return lang; }
/** * Guess the preferred lang in the langs set passed as argument. * The first Lang that matches an available Lang wins, otherwise returns the first Lang available in this application. * * @param app the currept application * @param availableLangs the set of langs from which to guess the preferred * @return the preferred lang. */ public static Lang preferred(Application app, List<Lang> availableLangs) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); Stream<Lang> stream = availableLangs.stream(); List<play.api.i18n.Lang> langSeq = stream.map(l -> new play.api.i18n.Lang(l.toLocale())).collect(toList()); return new Lang(langs.preferred(Scala.toSeq(langSeq))); } }
/** * Guess the preferred lang in the langs set passed as argument. * The first Lang that matches an available Lang wins, otherwise returns the first Lang available in this application. * * @param app the currept application * @param availableLangs the set of langs from which to guess the preferred * @return the preferred lang. */ public static Lang preferred(Application app, List<Lang> availableLangs) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); Stream<Lang> stream = availableLangs.stream(); List<play.api.i18n.Lang> langSeq = stream.map(l -> new play.api.i18n.Lang(l.toLocale())).collect(toList()); return new Lang(langs.preferred(Scala.toSeq(langSeq))); } }
/** * Guess the preferred lang in the langs set passed as argument. * The first Lang that matches an available Lang wins, otherwise returns the first Lang available in this application. * * @param app the currept application * @param availableLangs the set of langs from which to guess the preferred * @return the preferred lang. */ public static Lang preferred(Application app, List<Lang> availableLangs) { play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class); Stream<Lang> stream = availableLangs.stream(); List<play.api.i18n.Lang> langSeq = stream.map(l -> new play.api.i18n.Lang(l.toLocale())).collect(toList()); return new Lang(langs.preferred(Scala.toSeq(langSeq))); } }