aboutsummaryrefslogtreecommitdiffstats
path: root/library/intl/src/LocaleResolverTrait.php
diff options
context:
space:
mode:
authorRedMatrix <info@friendica.com>2014-12-31 10:43:19 +1100
committerRedMatrix <info@friendica.com>2014-12-31 10:43:19 +1100
commit4f35efa0bad4ae6489b63f3eebafe6542d654094 (patch)
treefdf7577c0b602a1f8b86401572e53cfe90cf2474 /library/intl/src/LocaleResolverTrait.php
parentae9d08267c632cae36a4ebd34c2077fd0051e0e7 (diff)
downloadvolse-hubzilla-4f35efa0bad4ae6489b63f3eebafe6542d654094.tar.gz
volse-hubzilla-4f35efa0bad4ae6489b63f3eebafe6542d654094.tar.bz2
volse-hubzilla-4f35efa0bad4ae6489b63f3eebafe6542d654094.zip
Revert "Language names via intl library."
Diffstat (limited to 'library/intl/src/LocaleResolverTrait.php')
-rw-r--r--library/intl/src/LocaleResolverTrait.php89
1 files changed, 0 insertions, 89 deletions
diff --git a/library/intl/src/LocaleResolverTrait.php b/library/intl/src/LocaleResolverTrait.php
deleted file mode 100644
index 21c463c7e..000000000
--- a/library/intl/src/LocaleResolverTrait.php
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-
-namespace CommerceGuys\Intl;
-
-use CommerceGuys\Intl\Exception\UnknownLocaleException;
-
-trait LocaleResolverTrait
-{
- /**
- * The path where per-locale definitions are stored.
- */
- protected $definitionPath;
-
- /**
- * Determines which locale should be used for loading definitions.
- *
- * If the "bs-Cyrl-BA" locale is requested, with an "en" fallback,
- * the system will try to find the definitions for:
- * 1) bs-Cyrl-BA
- * 2) bs-Cyrl
- * 3) bs
- * 4) en
- * The first locale for which a definition file is found, wins.
- * Otherwise, an exception is thrown.
- *
- * @param string $locale The desired locale (i.e. fr-FR).
- * @param string $fallbackLocale A fallback locale (i.e "en").
- *
- * @return string
- *
- * @throws UnknownLocaleException
- */
- protected function resolveLocale($locale = null, $fallbackLocale = null)
- {
- if (is_null($locale)) {
- // Use the default locale if none was provided.
- // @todo Provide a way to override this.
- $locale = 'en';
- }
- // Normalize the locale. Allows en_US to work the same as en-US, etc.
- $locale = str_replace('_', '-', $locale);
- // List all possible variants (i.e. en-US gives "en-US" and "en").
- $localeVariants = $this->getLocaleVariants($locale);
- // A fallback locale was provided, add it to the end of the chain.
- if (isset($fallbackLocale)) {
- $localeVariants[] = $fallbackLocale;
- }
-
- // Try to resolve a locale by finding a matching definition file.
- $resolvedLocale = null;
- foreach ($localeVariants as $localeVariant) {
- $path = $this->definitionPath . $localeVariant . '.json';
- if (file_exists($path)) {
- $resolvedLocale = $localeVariant;
- break;
- }
- }
- // No locale could be resolved, stop here.
- if (!$resolvedLocale) {
- throw new UnknownLocaleException($locale);
- }
-
- return $resolvedLocale;
- }
-
- /**
- * Returns all variants of a locale.
- *
- * For example, "bs-Cyrl-BA" has the following variants:
- * 1) bs-Cyrl-BA
- * 2) bs-Cyrl
- * 3) bs
- *
- * @param string $locale The locale (i.e. fr-FR).
- *
- * @return array An array of all variants of a locale.
- */
- protected function getLocaleVariants($locale)
- {
- $localeVariants = array();
- $localeParts = explode('-', $locale);
- while (!empty($localeParts)) {
- $localeVariants[] = implode('-', $localeParts);
- array_pop($localeParts);
- }
-
- return $localeVariants;
- }
-}