Utility
class Utility (View source)
The Utility class for locale specific actions
Constants
PATTERN_MATCH_ACCEPTLANGUAGE |
A pattern which matches HTTP Accept-Language Headers |
Methods
Parses Accept-Language header and returns array of locale tags (like: en-GB, en), or false if no tags were found.
Extracts a locale tag (identifier) from the filename given.
Extracts a locale tag (identifier) from the directory name given.
Checks if $haystack string begins with $needle string.
Checks if $haystack string ends with $needle string.
Details
static mixed
parseAcceptLanguageHeader(string $acceptLanguageHeader)
Parses Accept-Language header and returns array of locale tags (like: en-GB, en), or false if no tags were found.
This method only returns tags that conforms ISO 639 for language codes and ISO 3166 for region codes. HTTP spec (RFC 2616) defines both of these parts as 1*8ALPHA, but this method ignores tags with longer (or shorter) codes than defined in ISO mentioned above.
There can be an asterisk "*" in the returned array, which means that any language is acceptable.
Warning: This method expects that locale tags are placed in descending order by quality in the $header string. I'm not sure if it's always true with the web browsers.
static mixed
extractLocaleTagFromFilename(string $filename)
Extracts a locale tag (identifier) from the filename given.
Locale tag should be placed just before the extension of the file. For example, filename bar.png can be localized as bar.en_GB.png, and this method extracts en_GB from the name.
Note: this ignores matches on rss, xml and php and validates the identifier.
static mixed
extractLocaleTagFromDirectory(string $directory)
Extracts a locale tag (identifier) from the directory name given.
Note: Locale tag will be extracted from the last directory path segment only.
static bool
stringBeginsWith(string $haystack, string $needle)
Checks if $haystack string begins with $needle string.
static bool
stringEndsWith(string $haystack, string $needle)
Checks if $haystack string ends with $needle string.