Created
February 22, 2017 12:35
-
-
Save cozingo/bcca314d44fd302bd041c18414f73cd6 to your computer and use it in GitHub Desktop.
insert Yii:t messages to database
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
$messages_arr = [ | |
'ru' => require('../../common/messages/ru/main.php'), | |
'en' => require('../../common/messages/en/main.php'), | |
'uz' => require('../../common/messages/uz/main.php'), | |
]; | |
foreach ($messages_arr as $lang => $messages) { | |
foreach ($messages as $key=>$value){ | |
$sm = SourceMessage::find()->where(['message'=>$key, 'category' => 'main'])->one(); | |
if($sm){ | |
$mid = $sm->id; | |
} else { | |
$nsm = new SourceMessage(); | |
$nsm->category = 'main'; | |
$nsm->message = $key; | |
$nsm->save(); | |
$mid = $nsm->id; | |
} | |
$msg = \common\models\Message::find()->where(['id' => $mid, 'language' => $lang])->one(); | |
if(!$msg){ | |
$msg = new \common\models\Message(); | |
$msg->id = $mid; | |
$msg->language = $lang; | |
} | |
$msg->translation = $value; | |
$msg->save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment