Last active
November 7, 2022 11:05
-
-
Save ChVuagniaux/868caf23f7b2a34c47f4ed62d922c133 to your computer and use it in GitHub Desktop.
Translate OctoberCMS RainLab.Location (https://octobercms.com/plugin/rainlab-location) Countries via https://RESTcountries.eu API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use RainLab\Location\Models\Country; | |
Route::get('generate-country-translations', function () { | |
$countries = Country::all(); | |
$countries->each(function (Country $country) { | |
$response = file_get_contents("https://restcountries.com/v2/alpha/{$country->code}"); | |
$countryInformations = json_decode($response); | |
$country->setAttributeTranslated('name', $countryInformations->translations->fr, 'fr'); | |
$country->setAttributeTranslated('name', $countryInformations->name, 'en'); | |
$country->setAttributeTranslated('name', $countryInformations->translations->de, 'de'); | |
$country->setAttributeTranslated('name', $countryInformations->name, 'pt'); | |
$country->save(); | |
}); | |
return response('end'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment