• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
language file inside a folder

#1
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.
Reply

#2
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.
Test your translation files with Translation Tester
Reply

#3
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.
Reply

#4
(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?
Test your translation files with Translation Tester
Reply

#5
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);
    }

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.