Codeigniter3中出现意外错误

时间:2018-02-12 06:43:33

标签: php codeigniter multilingual

我写了代码

$this->session->set_flashdata('nt_changed_msg','<div class="alert alert-danger text-center">'.lang('tekparerr').'</div>');
redirect('user/continueregistration');

在我的User.php控制器中。但是,它给出了一个错误:

  

无法加载请求的语言文件:   语言/阿塞拜疆/ form_validation_lang.php

实际上,我无法理解,如果我没有请求form_validation_lang.php并且我的语言文件夹中没有此文件,为什么Codeigniter需要它?我该如何解决这个问题?

我的挂钩文件:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class LanguageLoader
{
    function initialize() {
        $ci =& get_instance();
        $ci->load->helper('language');
        $siteLang = $ci->session->userdata('site_lang');
        $ci->config->set_item('language', $siteLang);
        if ($siteLang) {
            $ci->lang->load('header',$siteLang);
            $ci->lang->load('footer',$siteLang);
            $ci->lang->load('index',$siteLang);
            $ci->lang->load('courses',$siteLang);
            $ci->lang->load('parsleyvalidator',$siteLang);
            $ci->lang->load('blog',$siteLang);
            $ci->lang->load('instructors',$siteLang);
            $ci->lang->load('continuereg',$siteLang);
            $ci->lang->load('about',$siteLang);
            $ci->lang->load('contact',$siteLang);
            $ci->lang->load('controllers',$siteLang);
            $ci->lang->load('form_validation',$siteLang);
            $ci->lang->load('mailtemplate',$siteLang);
        } else {
            $ci->lang->load('header','azerbaijani');
            $ci->lang->load('footer','azerbaijani');
            $ci->lang->load('index','azerbaijani');
            $ci->lang->load('courses','azerbaijani');
            $ci->lang->load('parsleyvalidator','azerbaijani');
            $ci->lang->load('blog','azerbaijani');
            $ci->lang->load('instructors','azerbaijani');
            $ci->lang->load('continuereg','azerbaijani');
            $ci->lang->load('about','azerbaijani');
            $ci->lang->load('contact','azerbaijani');
            $ci->lang->load('controllers','azerbaijani');
            $ci->lang->load('form_validation','azerbaijani');
            $ci->lang->load('mailtemplate','azerbaijani');
        }
        // cierrors
    }
}

1 个答案:

答案 0 :(得分:0)

如果你查看system / libraries / Form_validation.php,你会看到以下行(450):

$this->CI->lang->load('form_validation');

CodeIgniter表单验证不允许您专门为表单验证指定语言,并且它需要一个lang文件,因此您最好的选择是创建一个。

创建文件application/language/azerbaijani/form_validation_lang.php,然后在该文件中复制system/language/english/form_validation_lang.php的内容。由于您最好将英语翻译成阿塞拜疆语,请更新您的新阿塞拜疆语/ form_validation_lang.php文件,以便内容采用阿塞拜疆语。

供参考,这是form_validation_lang.php文件的英文相关内容:

<?php
$lang['form_validation_required']              = 'The {field} field is required.';
$lang['form_validation_isset']                 = 'The {field} field must have a value.';
$lang['form_validation_valid_email']           = 'The {field} field must contain a valid email address.';
$lang['form_validation_valid_emails']          = 'The {field} field must contain all valid email addresses.';
$lang['form_validation_valid_url']             = 'The {field} field must contain a valid URL.';
$lang['form_validation_valid_ip']              = 'The {field} field must contain a valid IP.';
$lang['form_validation_min_length']            = 'The {field} field must be at least {param} characters in length.';
$lang['form_validation_max_length']            = 'The {field} field cannot exceed {param} characters in length.';
$lang['form_validation_exact_length']          = 'The {field} field must be exactly {param} characters in length.';
$lang['form_validation_alpha']                 = 'The {field} field may only contain alphabetical characters.';
$lang['form_validation_alpha_numeric']         = 'The {field} field may only contain alpha-numeric characters.';
$lang['form_validation_alpha_numeric_spaces']  = 'The {field} field may only contain alpha-numeric characters and spaces.';
$lang['form_validation_alpha_dash']            = 'The {field} field may only contain alpha-numeric characters, underscores, and dashes.';
$lang['form_validation_numeric']               = 'The {field} field must contain only numbers.';
$lang['form_validation_is_numeric']            = 'The {field} field must contain only numeric characters.';
$lang['form_validation_integer']               = 'The {field} field must contain an integer.';
$lang['form_validation_regex_match']           = 'The {field} field is not in the correct format.';
$lang['form_validation_matches']               = 'The {field} field does not match the {param} field.';
$lang['form_validation_differs']               = 'The {field} field must differ from the {param} field.';
$lang['form_validation_is_unique']             = 'The {field} field must contain a unique value.';
$lang['form_validation_is_natural']            = 'The {field} field must only contain digits.';
$lang['form_validation_is_natural_no_zero']    = 'The {field} field must only contain digits and must be greater than zero.';
$lang['form_validation_decimal']               = 'The {field} field must contain a decimal number.';
$lang['form_validation_less_than']             = 'The {field} field must contain a number less than {param}.';
$lang['form_validation_less_than_equal_to']    = 'The {field} field must contain a number less than or equal to {param}.';
$lang['form_validation_greater_than']          = 'The {field} field must contain a number greater than {param}.';
$lang['form_validation_greater_than_equal_to'] = 'The {field} field must contain a number greater than or equal to {param}.';
$lang['form_validation_error_message_not_set'] = 'Unable to access an error message corresponding to your field name {field}.';
$lang['form_validation_in_list']               = 'The {field} field must be one of: {param}.';

有关详细信息,请参阅:https://www.codeigniter.com/userguide3/libraries/language.html