Beispiel #1
0
 /**
  * Get a list of localized timezone names
  *
  * @return array
  */
 public static function getList()
 {
     $xoops = \Xoops::getInstance();
     $locale = \Xoops\Locale::getCurrent();
     $key = ['system', 'lists', 'timezone', $locale];
     //$xoops->cache()->delete($key);
     $timeZones = $xoops->cache()->cacheRead($key, function () {
         $timeZones = array();
         $territories = Territory::getContinentsAndCountries();
         $maxLen = 0;
         $utcDtz = new \DateTimeZone('UTC');
         foreach ($territories as $byContinent) {
             $continent = $byContinent['name'];
             foreach ($byContinent['children'] as $cCode => $cName) {
                 $allZones = $utcDtz->listIdentifiers(\DateTimeZone::PER_COUNTRY, $cCode);
                 foreach ($allZones as $zone) {
                     $maxLen = max(strlen($zone), $maxLen);
                     $name = Calendar::getTimezoneExemplarCity($zone);
                     if (!isset($timeZones[$zone]) && !empty($name)) {
                         $timeZones[$zone] = $continent . '/' . $name;
                     }
                 }
             }
         }
         \XoopsLocale::asort($timeZones);
         $default = array('UTC' => Calendar::getTimezoneNameNoLocationSpecific(new \DateTimeZone('GMT')));
         $timeZones = array_merge($default, $timeZones);
         return $timeZones;
     });
     return $timeZones;
 }
 public function __construct()
 {
     $countries = \Punic\Territory::getCountries();
     unset($countries['IM'], $countries['JE']);
     $event = new \Symfony\Component\EventDispatcher\GenericEvent();
     $event->setArgument('countries', $countries);
     $event = Events::dispatch('on_get_countries_list', $event);
     $countries = $event->getArgument('countries');
     $this->countries = $countries;
 }
 private function isNativeTranslation($translation)
 {
     if ($translation instanceof RegionTranslation) {
         $country = $translation->region->country->code;
     } elseif ($translation instanceof CountryTranslation) {
         $country = $translation->country->code;
     } else {
         return;
     }
     $locale = str_replace('-', '_', $translation->locale);
     $languages = Territory::getLanguages($country, 'of', true);
     $languages[] = $locale . '_' . $country;
     $translation->is_native = in_array($locale, $languages);
 }
Beispiel #4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('countries')->delete();
     $locales = Config::get('translatable.locales');
     // $locales = get_locales(true);
     $countries = Territory::getCountries('en');
     $producing = ['AL', 'AM', 'AR', 'AT', 'AU', 'AZ', 'BA', 'BE', 'BG', 'BO', 'BR', 'BY', 'CA', 'CH', 'CL', 'CN', 'CU', 'CY', 'CZ', 'DE', 'DZ', 'EE', 'EG', 'ES', 'ET', 'FR', 'GB', 'GE', 'GR', 'HR', 'HU', 'IL', 'IT', 'JO', 'JP', 'KG', 'KZ', 'LB', 'LI', 'LT', 'LU', 'LV', 'LY', 'MA', 'MD', 'ME', 'MG', 'MK', 'MT', 'MX', 'NZ', 'PA', 'PE', 'PT', 'PY', 'RE', 'RO', 'RS', 'RU', 'SI', 'SK', 'SY', 'TJ', 'TM', 'TN', 'TR', 'UA', 'US', 'UY', 'UZ', 'VN', 'ZA', 'ZW', 'CSHH', 'CSXX', 'SUHH', 'YUCS'];
     foreach ($countries as $code => $void) {
         $country = ['code' => $code, 'is_wine' => in_array($code, $producing)];
         $nameEn = Territory::getName($code, 'en');
         foreach ($locales as $key => $locale) {
             if (is_array($locale)) {
                 $country[$key] = ['name' => Territory::getName($code, $key)];
                 foreach ($locale as $countryLocale) {
                     $name = Territory::getName($code, $key . '-' . $countryLocale);
                     if ($name != $country[$key]['name'] && $name != $nameEn) {
                         $country[$key . '-' . $countryLocale] = ['name' => $name];
                     }
                 }
             } else {
                 $name = Territory::getName($code, $locale);
                 if ($name != $nameEn) {
                     $country[$locale] = ['name' => $name];
                 }
             }
         }
         $country = Country::create($country);
         $langs = Territory::getLanguages($code, 'of', true);
         $langs = array_map(function ($lang) {
             return str_replace('_', '-', $lang);
         }, $langs);
         $langs = array_diff($langs, get_locales(true));
         foreach ($langs as $lang) {
             $name = Territory::getName($code, str_replace('-', '_', $lang));
             $translation = $country->getNewTranslation($lang);
             $translation->name = $name;
             $translation->country_id = $country->id;
             $translation->save();
         }
     }
     $countries = ['CSHH' => 'Czechoslovakia', 'CSXX' => 'Serbia and Montenegro', 'SUHH' => 'Soviet Union', 'YUCS' => 'Yugoslavia'];
     foreach ($countries as $code => $name) {
         $country = ['code' => $code, 'is_wine' => in_array($code, $producing), 'en' => ['name' => $name]];
         $country = Country::create($country);
     }
 }
Beispiel #5
0
 public function languageAndCurrencyByCountry($id)
 {
     $country = Country::find($id);
     if ($country) {
         $code = $country->code;
         $languages = PunicTerritory::getLanguages($code, 'of', true);
         $languages = array_map(function ($value) {
             return str_replace('_', '-', $value);
         }, $languages);
         $allLanguages = Language::lists('code')->toArray();
         $languages = array_intersect(array_merge((array) $languages, ['en']), $allLanguages);
         $language = head($languages);
         $allCurrencies = Currency::lists('code')->toArray();
         $currencies = PunicCurrency::getCurrencyForTerritory($code);
         $currencies = array_intersect(array_merge((array) $currencies, ['GBP']), $allCurrencies);
         $currency = head($currencies);
         $language = Language::whereCode($language)->first();
         $currency = Currency::whereCode($currency)->first();
         return ['language_id' => $language->id, 'currency_id' => $currency->id];
     } else {
         return response('error', 404);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function __construct(string $name, string $label = null)
 {
     parent::__construct($name, $label);
     self::translator()->addFile(__DIR__ . '/../../../lang/global', 'bootstrap');
     $this->add((new Group(self::trans('bootstrap.googlePlace/street')))->add($this->fields['number'] = (new Text($name . '[number]'))->setPlaceholder(self::trans('bootstrap.googlePlace/number')))->add($this->fields['street'] = (new Text($name . '[street]'))->setPlaceholder(self::trans('bootstrap.googlePlace/street'))))->add((new Group(Misc::joinUnits([self::trans('bootstrap.googlePlace/zipcode'), self::trans('bootstrap.googlePlace/city')])))->add($this->fields['zipcode'] = (new Text($name . '[zipcode]'))->setPlaceholder(self::trans('bootstrap.googlePlace/zipcode')))->add($this->fields['city'] = (new Text($name . '[city]'))->setPlaceholder(self::trans('bootstrap.googlePlace/city'))))->add($this->fields['state'] = new Text($name . '[state]', self::trans('bootstrap.googlePlace/state')))->add($this->fields['country'] = new Select($name . '[country]', self::trans('bootstrap.googlePlace/country'), Territory::getCountries()))->add($this->fields['lat'] = new Hidden($name . '[lat]'))->add($this->fields['long'] = new Hidden($name . '[long]'));
 }
Beispiel #7
0
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
 * @link      http://xoops.org
 */
include dirname(dirname(__DIR__)) . '/mainfile.php';
$xoops = Xoops::getInstance();
$xoops->header();
$country = Request::getString('country', 'US');
$form = new Xoops\Form\ThemeForm('Show Flag for a Country', 'form_flag', '', 'post', false, 'horizontal');
$ccode = new Xoops\Form\SelectCountry('Country', 'country', $country);
$form->addElement($ccode, false);
$button = new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit');
$form->addElement($button);
$form->display();
// demonstrate the CountryFlags service
$img = $xoops->service('countryflag')->getImgTag($country)->getValue();
echo $img;
// we can specify a size
$img = $xoops->service('countryflag')->getImgTag($country, null, 'medium')->getValue();
echo $img;
$img = $xoops->service('countryflag')->getImgTag($country, null, 'small')->getValue();
echo $img;
echo '<br /><br />';
// we can add any HTML attributes to the img tag
$attributes = ['class' => 'img-polaroid', 'title' => Territory::getName($country)];
$img = $xoops->service('countryflag')->getImgTag($country, $attributes)->getValue();
echo $img . '<br /><br />';
if (!$xoops->service('countryflag')->isAvailable()) {
    echo 'Please install a countryflag provider to view this demonstration.';
}
\Xoops\Utils::dumpFile(__FILE__);
$xoops->footer();
Beispiel #8
0
 /**
  * Returns a keyed array of timezone identifiers (keys are the standard PHP timezone names, values are the localized timezone names).
  *
  * @return array
  *
  * @see http://www.php.net/datetimezone.listidentifiers.php
  */
 public function getTimezones()
 {
     static $cache = array();
     $locale = Localization::activeLocale();
     if (array_key_exists($locale, $cache)) {
         $result = $cache[$locale];
     } else {
         $result = array();
         $continentNames = array('Africa' => \Punic\Territory::getName('002'), 'Asia' => \Punic\Territory::getName('142'), 'America' => \Punic\Territory::getName('019'), 'Antarctica' => \Punic\Territory::getName('AQ'), 'Arctic' => t('Arctic'), 'Atlantic' => t('Atlantic Ocean'), 'Australia' => \Punic\Territory::getName('AU'), 'Europe' => \Punic\Territory::getName('150'), 'Indian' => t('Indian Ocean'), 'Pacific' => t('Pacific Ocean'));
         foreach (\DateTimeZone::listIdentifiers() as $timezoneID) {
             switch ($timezoneID) {
                 case 'UTC':
                 case 'GMT':
                     $timezoneName = t('Greenwich Mean Time');
                     break;
                 default:
                     $chunks = explode('/', $timezoneID);
                     if (array_key_exists($chunks[0], $continentNames)) {
                         $chunks[0] = $continentNames[$chunks[0]];
                     }
                     if (count($chunks) > 0) {
                         $city = \Punic\Calendar::getTimezoneExemplarCity($timezoneID, false);
                         if (!strlen($city)) {
                             switch ($timezoneID) {
                                 case 'Antarctica/South_Pole':
                                     $city = t('South Pole');
                                     break;
                                 case 'America/Montreal':
                                     $city = t('Montreal');
                                     break;
                                 case 'America/Shiprock':
                                     $city = t('Shiprock');
                                     break;
                             }
                         }
                         if (strlen($city)) {
                             $chunks = array($chunks[0], $city);
                         }
                     }
                     $timezoneName = implode('/', $chunks);
                     break;
             }
             $result[$timezoneID] = $timezoneName;
         }
         natcasesort($result);
         $cache[$locale] = $result;
     }
     return $result;
 }
 /**
  * Return a list of territory codes where a specific language is spoken, sorted by the total number of people speaking that language.
  *
  * @param string $languageCode The language code (eg. 'en')
  *
  * @return array Returns a list of country codes
  */
 public function getCountriesForLanguage($languageCode)
 {
     return \Punic\Territory::getTerritoriesForLanguage($languageCode);
 }
Beispiel #10
0
 function getName($key, $locale)
 {
     switch (@$_GET['type'] ?: 'country') {
         case 'language':
             return Punic\Language::getName($key, $locale);
         case 'currency':
             return Punic\Currency::getName($key, null, $locale);
         default:
             return Punic\Territory::getName($key, $locale);
     }
 }
Beispiel #11
0
    $countries = new Illuminate\Support\Collection($countries);
    $countries = $countries->sortBy('coll');
    foreach ($countries as $country) {
        echo $country['pinyin'] . '<br>';
    }
    return ' ';
    dd($countries);
});
Route::get('/test/region-names', function () {
    die;
    $translations = RegionTranslation::with('region.country')->get();
    //->where('id', '>', 640)->limit(10)
    foreach ($translations as $translation) {
        $locale = str_replace('-', '_', $translation->locale);
        $country = $translation->region->country->code;
        $languages = Territory::getLanguages($country, 'of', true);
        $languages[] = $locale . '_' . $country;
        $translation->is_native = in_array($locale, $languages);
        $translation->save();
    }
    return $translations;
    $regions = Region::whereTranslation('name', 'Wienn')->get();
    foreach ($regions as $region) {
        $names = ['en' => ['name' => 'Vienna'], 'de' => ['name' => 'Wien']];
        $region->fill($names);
        $region->save();
    }
    echo '<pre>';
    echo $regions->toJson(JSON_PRETTY_PRINT);
    echo '</pre>';
});
Beispiel #12
0
 /**
  * Get a list of localized country names
  *
  * @return array
  */
 public static function getList()
 {
     $countryList = Territory::getCountries();
     \XoopsLocale::asort($countryList);
     return $countryList;
 }