查看:Lang_view.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CodeIgniter Internationalization Example</title>
</head>
<body>
<?php
form_open('lang');
?>
<select name='language' onchange='javascript:this:form:submit();'>
<?php
$lang = array('english'=>'English','french'=>'French','german'=>'German');
foreach($lang as $key => $val){
if($key == $language){
echo "<option value='".$key."' selected>".$val."</option>";}
else
echo "<option value='".$key."'>".$val."</option>";
}
?>
</select>
<?php form_close(); echo $msg ;?>
</body>
</html>
控制器:Lang_controller
class Lang_controller扩展CI_Controller {
public function index(){
$this->load->helper('form');
$language = $this->input->post('language');
if($language == 'french')
$this->lang->load('french_lang','french');
else if ($language == 'german'){
$this->lang->load('german_lang','german');
}
else
$this->lang->load('english_lang','english');
$data = array(
'msg' => $this->lang->line('msg'),
'language' => $language
);
$this->load->view('lang_view',$data);
}
}
我在应用程序/语言中创建了三个不同的语言文件夹。当我点击任何其他语言时,除了英语之外,我无法生成输出。
答案 0 :(得分:0)
在这里,您需要更改默认语言。
//change system default language dynamically
$language = $this->input->post('language');
$this->config->set_item('language', $language );
答案 1 :(得分:0)
要在codeigniter中启动表单,您需要在form_open
之前编写from __future__ import unicode_literals
from django.db import models
# Create your models here.
class CollectionModel(models.Model):
parent = models.ForeignKey('self', on_delete=models.CASCADE)
echo