CodeIgniter Forums

Full Version: language file inside a folder
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey people!

I can use:
PHP Code:
lang('Errors.errorEmailMissing'); 

But, image that Errors.php is inside "app/Language/en/mysite/Errors.php". Now, how can I call the language?

PHP Code:
lang('mysite.Errors.errorEmailMissing'); //doesn't work, for example
lang('mysite/Errors.errorEmailMissing'); //too 

I need this because I want to use the same viewers files paths.
I don’t think that’s possible. Why do you want a “mysite” subdirectory? You are in app/Language, this is already your site’s language folder.
Thanks for help.

My site was an exemple. Can be admin or user folder too.

I already solved the problem seeing How CI do the things inside lang().

Thanks.
(04-12-2020, 08:11 PM)George Rangel Wrote: [ -> ]Thanks for help.

My site was an exemple. Can be admin or user folder too.

I already solved the problem seeing How CI do the things inside lang().

Thanks.

That’s cool. Care to share your solution?
PHP Code:
//in ShowPage class
$dadosView['lang'] = getpagelang($template$_SESSION['lang']); 
PHP Code:
<?php

namespace App\Helpers;

    /**
     * obtém todas as traduções de uma linguagem
     * @access public
     * @param String $page arquivo com o mesmo nome do Controller
     * @param String $lang linguagem em questão
     * @return Array
     */
    function getpagelang($page$lang): Array
    {       
        
//caminho do arquivo a ser lido
        $file LANGUAGE_PATH.$lang.DIRECTORY_SEPARATOR$page '.php';

        //se o arquivo existir, retorna o conteúdo
        if (file_exists($file)) {

            //obtém os dados do arquivo de linguagem
            $arrLang = include $file;

            //verifica se é um array para retornar
            if(is_array($arrLang)) return $arrLang;
            else return array();

        } else echo lang('Errors.LangFile', [], $lang);

        //se o arquivo não existir, retorna um array vazio
        return array();
    

them, in controller:

PHP Code:
<?php

namespace App\Controllers;

use 
App\Libraries\ShowPage;

class 
Contato extends BaseController
{
    
/**
     * Mostra a página inicial para este método
     */
    
public function index(): void
    
{
        
//chama o conteúdo da página
        
$template 'site' DIRECTORY_SEPARATOR 'Contato';
        
$menuWhere 'contato';
        new 
ShowPage($template$menuWhere);
    }