Return the list of languages spoken in a territory.
public static getLanguages ( string $territoryCode, string $filterStatuses = '', string $onlyCodes = false ) : array | null | ||
$territoryCode | string | The territory code |
$filterStatuses | string | Filter language status.
|
$onlyCodes | string | Set to true to retrieve only the language codes. If set to false (default) you'll receive a list of arrays with these keys:
|
Résultat | array | null | Return the languages spoken in the specified territory, as described by the $onlyCodes parameter (or null if $territoryCode is not valid or no data is available) |
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); }
/** * 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); } }
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); } }
$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>'; });