Skip to content

Instantly share code, notes, and snippets.

@cozingo
Created February 22, 2017 12:35
Show Gist options
  • Save cozingo/bcca314d44fd302bd041c18414f73cd6 to your computer and use it in GitHub Desktop.
Save cozingo/bcca314d44fd302bd041c18414f73cd6 to your computer and use it in GitHub Desktop.
insert Yii:t messages to database
$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