/** * Create a new version of this object with the given transient language set. * The transient language will be taken into account when using {@link MessagesApi#preferred(RequestHeader)}} (It will take precedence over any other language). * * @param locale The language to use. * @return The new version of this object with the given transient language set. */ default RequestHeader withTransientLang(Locale locale) { return addAttr(Messages.Attrs.CurrentLang, new 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; } }
/** * Create a new version of this object with the given transient language set. * The transient language will be taken into account when using {@link MessagesApi#preferred(RequestHeader)}} (It will take precedence over any other language). * * @param locale The language to use. * @return The new version of this object with the given transient language set. */ default RequestHeader withTransientLang(Locale locale) { return addAttr(Messages.Attrs.CurrentLang, new 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; } }
/** * 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; } }
@Inject public Langs(play.api.i18n.Langs langs) { this.langs = langs; List<Lang> availables = new ArrayList<>(); for (play.api.i18n.Lang lang : Scala.asJava(langs.availables())) { availables.add(new Lang(lang)); } this.availables = Collections.unmodifiableList(availables); }
@Inject public Langs(play.api.i18n.Langs langs) { this.langs = langs; List<Lang> availables = new ArrayList<>(); for (play.api.i18n.Lang lang : Scala.asJava(langs.availables())) { availables.add(new Lang(lang)); } this.availables = Collections.unmodifiableList(availables); }
@Inject public Langs(play.api.i18n.Langs langs) { this.langs = langs; List<Lang> availables = new ArrayList<>(); for (play.api.i18n.Lang lang : Scala.asJava(langs.availables())) { availables.add(new Lang(lang)); } this.availables = Collections.unmodifiableList(availables); }
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; }
@Inject public Langs(play.api.i18n.Langs langs) { this.langs = langs; List<Lang> availables = new ArrayList<Lang>(); for (play.api.i18n.Lang lang : JavaConversions.asJavaIterable(langs.availables())) { availables.add(new Lang(lang)); } this.availables = Collections.unmodifiableList(availables); }
/** * Get a messages context appropriate for the given candidates. * * Will select a language from the candidates, based on the languages available, and fallback to the default language * if none of the candidates are available. */ public Messages preferred(Http.RequestHeader request) { play.api.i18n.Messages msgs = messages.preferred(request); return new Messages(new Lang(msgs.lang()), this); }
/** * Get a messages context appropriate for the given request. * * Will select a language from the request, based on the languages available, and fallback to the default language * if none of the candidates are available. * * @param request the incoming request * @return the preferred messages context for the request */ public Messages preferred(Http.RequestHeader request) { play.api.i18n.Messages msgs = messages.preferred(request); return new MessagesImpl(new Lang(msgs.lang()), this); }
/** * Get a messages context appropriate for the given request. * * Will select a language from the request, based on the languages available, and fallback to the default language * if none of the candidates are available. * * @param request the incoming request * @return the preferred messages context for the request */ public Messages preferred(Http.RequestHeader request) { play.api.i18n.Messages msgs = messages.preferred(request); return new MessagesImpl(new Lang(msgs.lang()), this); }
/** * 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; }
/** * 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. */ public static Lang preferred(List<Lang> langs) { List<play.api.i18n.Lang> result = new ArrayList<play.api.i18n.Lang>(); for(play.i18n.Lang lang: langs) { result.add(lang.underlyingLang); } return new Lang(play.api.i18n.Lang.preferred(Scala.toSeq(result), play.api.Play.current())); }
/** * Get a messages context appropriate for the given candidates. * * Will select a language from the candidates, based on the languages available, and fallback to the default language * if none of the candidates are available. */ public Messages preferred(Collection<Lang> candidates) { Seq<Lang> cs = JavaConversions.collectionAsScalaIterable(candidates).toSeq(); play.api.i18n.Messages msgs = messages.preferred((Seq) cs); return new Messages(new Lang(msgs.lang()), this); }
/** * Select a preferred language, given the list of candidates. * * Will select the preferred language, based on what languages are available, or return the default language if * none of the candidates are available. * * @param candidates The candidate languages * @return The preferred language */ public Lang preferred(Collection<Lang> candidates) { return new Lang(langs.preferred((scala.collection.immutable.Seq) Scala.asScala(candidates).toSeq())); }
/** * Select a preferred language, given the list of candidates. * * Will select the preferred language, based on what languages are available, or return the default language if * none of the candidates are available. * * @param candidates The candidate languages * @return The preferred language */ public Lang preferred(Collection<Lang> candidates) { return new Lang(langs.preferred((scala.collection.immutable.Seq) Scala.asScala(candidates).toSeq())); }
/** * Select a preferred language, given the list of candidates. * * Will select the preferred language, based on what languages are available, or return the default language if * none of the candidates are available. * * @param candidates The candidate languages * @return The preferred language */ public Lang preferred(Collection<Lang> candidates) { return new Lang(langs.preferred((scala.collection.Seq) JavaConversions.collectionAsScalaIterable(candidates).toSeq())); } }
/** * Select a preferred language, given the list of candidates. * * Will select the preferred language, based on what languages are available, or return the default language if * none of the candidates are available. * * @param candidates The candidate languages * @return The preferred language */ public Lang preferred(Collection<Lang> candidates) { return new Lang(langs.preferred((scala.collection.immutable.Seq) Scala.asScala(candidates).toSeq())); }