Locales helper
In addition to the trait we also provide a helper class \Astrotomic\Translatable\Locales
it's a singleton service available as translatable.locales
and \Astrotomic\Translatable\Locales
.
This helper manages all locales available for translation and provides several methods.
This class also implements the ArrayAccess
interface to allow you to use it like a normal array.
Methods
load()
This method will (re)load all locales from the translatable.locales
config - it's called during service instantiation so you will only need it if you change the config during runtime.
all()
Alias: toArray()
Returns all available locales as an array - the structure differs from the config one, the return final generated array with combined country locales.
current()
Returns the current locale string.
has(string $locale)
Checks if the given locale is available in the configured set of locales.
get(string $locale)
Returns the provided locale or null
if it's not set.
add(string $locale)
Adds the given locale to the set of available locales.
forget(string $locale)
Removes the given locale of the available locales set.
getLocaleSeparator()
Returns the configured translatable.locale_separator
locale separator used to combine language with country locales.
getCountryLocale(string $locale, string $country)
Returns the formatted country based locale.
isLocaleCountryBased(string $locale)
Checks if the given locale is a country specific locale.
getLanguageFromCountryBasedLocale(string $locale)
Returns the language locale from given country based locale.
Last updated
Was this helpful?