/** * */ public function import(Request $request) { Excel::filter('chunk')->load($request->only('file')['file'], 'UTF-8')->chunk(100, function ($language) { // Loop through all rows $language->each(function ($row) { $default = Locale::find(1); $locales = Locale::lists('id', 'name'); $langs = []; foreach ($row as $lang => $translation) { if (array_key_exists(ucfirst($lang), $locales->toArray())) { // if imported lang exist $ilang_id = $locales[ucfirst($lang)]; // if ($ilang_id == $default->id) { $langs[ucfirst($lang)]['translation'] = $translation; $langs[ucfirst($lang)]['id'] = $ilang_id; } else { $langs['child'][ucfirst($lang)]['translation'] = $translation; $langs['child'][ucfirst($lang)]['id'] = $ilang_id; } } } $new_trans = LocaleTranslation::firstOrNew(['locale_id' => $langs[$default->name]['id'], 'translation' => $langs[$default->name]['translation']]); $new_trans->save(); foreach ($langs['child'] as $cland => $ctrans) { $new_ctrans = LocaleTranslation::firstOrNew(['locale_id' => $ctrans['id'], 'translation_id' => $new_trans->id]); $new_ctrans->translation = $ctrans['translation']; $new_ctrans->save(); } }); }); return redirect()->route('admin.language.index')->withFlashSuccess('Imported'); }
/** * Run the database seeds. * * @return void */ public function run() { // \App\Locale::create(['name' => 'english', 'code' => 'en', 'icon' => 'en.png']); \App\Locale::create(['name' => 'bahasa', 'code' => 'id', 'icon' => 'id.png']); \App\Locale::create(['name' => 'french', 'code' => 'fr', 'icon' => 'fr.png']); \App\Locale::create(['name' => 'rusian', 'code' => 'ru', 'icon' => 'ru.png']); }
public function initEnv(MvcEvent $e) { $sm = $e->getApplication()->getServiceManager(); /** @var Translator $translator */ $translator = $sm->get('App\\Translator'); $locale = $e->getRouteMatch()->getParam('locale', 'cs'); $translator->setLocale($locale); AbstractValidator::setDefaultTranslator($translator); \Locale::setDefault($locale); }
public function onBootstrap(MvcEvent $e) { Paginator::setDefaultItemCountPerPage(30); ini_set('html_errors', 'Off'); $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); $sm = $e->getApplication()->getServiceManager(); $em = $sm->get('doctrine.entitymanager.orm_default'); $auth = $sm->get('Zend\\Authentication\\AuthenticationService'); if (Cons::isConsole()) { $locale = locale_get_default(); } else { /* @var $al \Zend\Http\Header\Accept */ $al = $e->getRequest()->getHeaders('accept-language'); if ($al) { $locales = $al->getPrioritized(); $locale = reset($locales)->getTypeString(); \Locale::acceptFromHttp($locale); } else { $locale = locale_get_default(); } } /** @var Translator $translator */ $translator = $sm->get('MvcTranslator'); $translator->setLocale(mb_substr($locale, 0, 2)); // $translator->getEventManager()->attach('missingTranslation', array($this, 'translationListener')); AbstractValidator::setDefaultTranslator($translator); // // Narediti session tako, da se virtual hosti ne bodo med seboj mešali // da se avtentikacija ne prenaša med vhosti // poskrbim za identiteto uporabnika if ($e->getRequest() instanceof Request) { // handling autorizacij preko konzole $this->setIdentity('*****@*****.**', $auth, $em); } else { /* @var $request Request2 */ $request = $e->getRequest(); $header = $request->getHeader('Authorization'); if ($header instanceof Authorization && strlen($header->getFieldValue()) > 10) { $this->tryHttpAuth($auth, $em, $e); } } $identity = $auth->getIdentity(); $evm = $em->getEventManager(); $evm->addEventSubscriber(new RevisionsListener($sm, $identity)); $config = $sm->get('entity.metadata.factory')->getAllEntityConfig(); $evm->addEventSubscriber(new PrePersistListener($config)); }
public function updateTranslation(Request $request) { $lang_id = $request->get('lang_id'); //return $lang_id; die(); foreach ($lang_id as $id => $translation) { //return $id; die(); $translate = Translation::find($id); //return $translate;die(); if (!is_null($translate)) { //this is original or translated if (!is_null($translate->translation_id)) { //this is translated $original = $translate->original; } else { //this is original $original = $translate; } //return $original; die(); //$original->translated()->delete(); foreach ($translation as $lang => $string) { $locale = Locale::where('code', $lang)->first(); $child = Translation::firstOrNew(['locale_id' => $locale->id, 'translation_id' => $original->id]); $child->translation = $string; $child->original()->dissociate(); $child->locale()->dissociate(); $child->original()->associate($original); $child->locale()->associate($locale); $child->save(); } } else { $json['message'] = 'Something wrong!'; } } $json['status'] = true; $json['message'] = 'Translation updated!'; return json_encode($json); }
public function addLocale($locale) { $localeId = \App\Locale::where('lang', $locale)->first()->id; \Auth::user()->locales()->attach($localeId); }