/** * Get a {@code LanguageCode} that corresponds to a given * <a href="http://en.wikipedia.org/wiki/ISO_639-1">ISO 639-1</a> code * (2-letter lowercase code) or * <a href="http://en.wikipedia.org/wiki/ISO_639-2">ISO 639-2</a> code * (3-letter lowercase code). * * <p> * This method calls {@link #getByCode(String, boolean) getByCode}{@code (code, true)}. * Note that the behavior has changed since the version 1.13. In the older versions, * this method was an alias of {@code getByCode(code, false)}. * </p> * * @param code * An <a href="http://en.wikipedia.org/wiki/ISO_639-1">ISO 639-1</a> * code (2-letter lowercase code) or an * <a href="http://en.wikipedia.org/wiki/ISO_639-2">ISO 639-2</a> code * (3-letter lowercase code). Or "undefined" (case sensitive). * Note that if the given code is one of legacy language codes * ("iw", "ji" and "in"), it is treated as its official counterpart * ("he", "yi" and "id", respectively). For example, if "in" is given, * this method returns {@link #id LanguageCode.id}. * * @return * A {@code LanguageCode} instance, or {@code null} if not found. */ public static LanguageCode getByCode(String code) { return getByCode(code, true); }
/** * Get a {@code LanguageCode} that corresponds to a given * <a href="http://en.wikipedia.org/wiki/ISO_639-1">ISO 639-1</a> code * (2-letter lowercase code) or * <a href="http://en.wikipedia.org/wiki/ISO_639-2">ISO 639-2</a> code * (3-letter lowercase code). * * <p> * This method calls {@link #getByCode(String, boolean) getByCode}{@code (code, true)}. * Note that the behavior has changed since the version 1.13. In the older versions, * this method was an alias of {@code getByCode(code, false)}. * </p> * * @param code * An <a href="http://en.wikipedia.org/wiki/ISO_639-1">ISO 639-1</a> * code (2-letter lowercase code) or an * <a href="http://en.wikipedia.org/wiki/ISO_639-2">ISO 639-2</a> code * (3-letter lowercase code). Or "undefined" (case sensitive). * Note that if the given code is one of legacy language codes * ("iw", "ji" and "in"), it is treated as its official counterpart * ("he", "yi" and "id", respectively). For example, if "in" is given, * this method returns {@link #id LanguageCode.id}. * * @return * A {@code LanguageCode} instance, or {@code null} if not found. */ public static LanguageCode getByCode(String code) { return getByCode(code, true); }
/** * Get a {@code LanguageCode} that corresponds to a given * <a href="http://en.wikipedia.org/wiki/ISO_639-1">ISO 639-1</a> code * (2-letter lowercase code) or * <a href="http://en.wikipedia.org/wiki/ISO_639-2">ISO 639-2</a> code * (3-letter lowercase code). * * <p> * This method calls {@link #getByCode(String, boolean) getByCode}{@code (code, false)}. * </p> * * @param code * An <a href="http://en.wikipedia.org/wiki/ISO_639-1">ISO 639-1</a> * code (2-letter lowercase code) or an * <a href="http://en.wikipedia.org/wiki/ISO_639-2">ISO 639-2</a> code * (3-letter lowercase code). Or "undefined" (case insensitive). * Note that if the given code is one of legacy language codes * ("iw", "ji" and "in"), it is treated as its official counterpart * ("he", "yi" and "id", respectively). For example, if "in" is given, * this method returns {@link #id LanguageCode.id}. * * @return * A {@code LanguageCode} instance, or {@code null} if not found. * * @since 1.13 */ public static LanguageCode getByCodeIgnoreCase(String code) { return getByCode(code, false); }
/** * Get a {@code LanguageCode} that corresponds to a given * <a href="http://en.wikipedia.org/wiki/ISO_639-1">ISO 639-1</a> code * (2-letter lowercase code) or * <a href="http://en.wikipedia.org/wiki/ISO_639-2">ISO 639-2</a> code * (3-letter lowercase code). * * <p> * This method calls {@link #getByCode(String, boolean) getByCode}{@code (code, false)}. * </p> * * @param code * An <a href="http://en.wikipedia.org/wiki/ISO_639-1">ISO 639-1</a> * code (2-letter lowercase code) or an * <a href="http://en.wikipedia.org/wiki/ISO_639-2">ISO 639-2</a> code * (3-letter lowercase code). Or "undefined" (case insensitive). * Note that if the given code is one of legacy language codes * ("iw", "ji" and "in"), it is treated as its official counterpart * ("he", "yi" and "id", respectively). For example, if "in" is given, * this method returns {@link #id LanguageCode.id}. * * @return * A {@code LanguageCode} instance, or {@code null} if not found. * * @since 1.13 */ public static LanguageCode getByCodeIgnoreCase(String code) { return getByCode(code, false); }
/** * Get a {@code LanguageCode} that corresponds to the language code of * the given {@link Locale} instance. * * @param locale * A {@code Locale} instance. * * @return * A {@code LanguageCode} instance, or {@code null} if not found. * When {@link Locale#getLanguage() getLanguage()} method of the * given {@code Locale} instance returns {@code null} or an * empty string, {@link #undefined LanguageCode.undefined} is * returned. * * @see Locale#getLanguage() */ public static LanguageCode getByLocale(Locale locale) { if (locale == null) { return null; } // Locale.getLanguage() returns a lowercase ISO 639 code. String language = locale.getLanguage(); if (language == null || language.length() == 0) { return LanguageCode.undefined; } return getByCode(language, true); }
/** * Get a {@code LanguageCode} that corresponds to the language code of * the given {@link Locale} instance. * * @param locale * A {@code Locale} instance. * * @return * A {@code LanguageCode} instance, or {@code null} if not found. * When {@link Locale#getLanguage() getLanguage()} method of the * given {@code Locale} instance returns {@code null} or an * empty string, {@link #undefined LanguageCode.undefined} is * returned. * * @see Locale#getLanguage() */ public static LanguageCode getByLocale(Locale locale) { if (locale == null) { return null; } // Locale.getLanguage() returns a lowercase ISO 639 code. String language = locale.getLanguage(); if (language == null || language.length() == 0) { return LanguageCode.undefined; } return getByCode(language, true); }
/** * Get a list of {@code LocaleCode} instances whose language matches the given one. * * <p> * This method is an alias of {@link #getByLanguage(LanguageCode) * getByLanguage}{@code (}{@link LanguageCode}{@code .}{@link * LanguageCode#getByCode(String, boolean) getByCode}{@code (language, caseSensitive))}. * </p> * * @param language * Language code. ISO 639 alpha-2 or alpha-3. * * @param caseSensitive * If {@code true}, the given code should consist of lowercase letters only. * If {@code false}, case is ignored. * * @return * List of {@code LocaleCode} instances. If there is no {@code LocaleCode} * instance whose language matches the given one, the size of the returned * list is zero. * * @since 1.3 */ public static List<LocaleCode> getByLanguage(String language, boolean caseSensitive) { return getByLanguage(LanguageCode.getByCode(language, caseSensitive)); }
/** * Get a list of {@code LocaleCode} instances whose language matches the given one. * * <p> * This method is an alias of {@link #getByLanguage(LanguageCode) * getByLanguage}{@code (}{@link LanguageCode}{@code .}{@link * LanguageCode#getByCode(String, boolean) getByCode}{@code (language, caseSensitive))}. * </p> * * @param language * Language code. ISO 639 alpha-2 or alpha-3. * * @param caseSensitive * If {@code true}, the given code should consist of lowercase letters only. * If {@code false}, case is ignored. * * @return * List of {@code LocaleCode} instances. If there is no {@code LocaleCode} * instance whose language matches the given one, the size of the returned * list is zero. * * @since 1.3 */ public static List<LocaleCode> getByLanguage(String language, boolean caseSensitive) { return getByLanguage(LanguageCode.getByCode(language, caseSensitive)); }
/** * The language code setter. * * @param locale Optional. The desired language, consisting of an ISO 639 language code and an ISO 3166-1 alpha-2 * country code, joined by an underscore. For example: es_MX, meaning "Spanish (Mexico)". Provide this * parameter if you want the category metadata returned in a particular language. Note that, if locale * is not supplied, or if the specified language is not available, all strings will be returned in the * Spotify default language (American English). The locale parameter, combined with the country * parameter, may give odd results if not carefully matched. For example * {@code country=SE&locale=de_DE} will return a list of categories relevant to Sweden but as German * language strings. * @return A {@link GetCategoryRequest.Builder} * @see <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">Wikipedia: ISO 3166-1 alpha-2 country codes</a> * @see <a href="https://en.wikipedia.org/wiki/ISO_639">Wikipedia: ISO 639 language code</a> */ public Builder locale(final String locale) { assert (locale != null); assert (locale.contains("_")); String[] localeParts = locale.split("_"); assert (localeParts.length == 2); assert (LanguageCode.getByCode(localeParts[0]) != null); assert (CountryCode.getByCode(localeParts[1]) != null); return setQueryParameter("locale", locale); }
/** * The language code setter. * * @param locale Optional. The desired language, consisting of an ISO 639 language code and an ISO 3166-1 alpha-2 * country code, joined by an underscore. For example: es_MX, meaning "Spanish (Mexico)". Provide this * parameter if you want the category metadata returned in a particular language. Note that, if locale * is not supplied, or if the specified language is not available, all strings will be returned in the * Spotify default language (American English). The locale parameter, combined with the country * parameter, may give odd results if not carefully matched. For example * {@code country=SE&locale=de_DE} will return a list of categories relevant to Sweden but as German * language strings. * @return A {@link GetListOfFeaturedPlaylistsRequest.Builder}. * @see <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">Wikipedia: ISO 3166-1 alpha-2 country codes</a> * @see <a href="https://en.wikipedia.org/wiki/ISO_639">Wikipedia: ISO 639 language code</a> */ public Builder locale(final String locale) { assert (locale != null); assert (locale.contains("_")); String[] localeParts = locale.split("_"); assert (localeParts.length == 2); assert (LanguageCode.getByCode(localeParts[0]) != null); assert (CountryCode.getByCode(localeParts[1]) != null); return setQueryParameter("locale", locale); }
/** * The language code setter. * * @param locale Optional. The desired language, consisting of an ISO 639 language code and an ISO 3166-1 alpha-2 * country code, joined by an underscore. For example: es_MX, meaning "Spanish (Mexico)". Provide this * parameter if you want the category metadata returned in a particular language. Note that, if locale * is not supplied, or if the specified language is not available, all strings will be returned in the * Spotify default language (American English). The locale parameter, combined with the country * parameter, may give odd results if not carefully matched. For example * {@code country=SE&locale=de_DE} will return a list of categories relevant to Sweden but as German * language strings. * @return A {@link GetListOfCategoriesRequest.Builder} * @see <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">Wikipedia: ISO 3166-1 alpha-2 country codes</a> * @see <a href="https://en.wikipedia.org/wiki/ISO_639">Wikipedia: ISO 639 language code</a> */ public Builder locale(final String locale) { assert (locale != null); assert (locale.contains("_")); String[] localeParts = locale.split("_"); assert (localeParts.length == 2); assert (LanguageCode.getByCode(localeParts[0]) != null); assert (CountryCode.getByCode(localeParts[1]) != null); return setQueryParameter("locale", locale); }