Welcome Guest, Not a member yet? Register   Sign In
[solved] Loading another language
#1

[eluser]SPeed_FANat1c[/eluser]
Hi,

I will show you an example, of what I want to do:
Code:
public function test()
    {
        $this->load->language('main', 'english');
        $this->test2();
    }
    
    function test2()
    {
         $this->load->language('main', 'lietuviu');
         echo lang('privilegijos');
    }

I call function test1, which calls test2. I want it to translate to lithuanian language, but it translates to an english. How can I force it to load another language?
#2

[eluser]plain jane[/eluser]
Can you pls try this

Code:
public function test()
    {
        $this->test2();
    }
    
    function test2()
    {
         $this->load->language('main', 'lietuviu');
         echo lang('privilegijos');
    }

Thanks,
ci user
#3

[eluser]SPeed_FANat1c[/eluser]
that worked. But then its interesting why the same does not work in my real functions. Ok, I will try to debug that later.

But now the next question - if my function is such:

Code:
function test2()
    {
        
        
         $this->load->language('main', 'english');
         $this->load->language('main', 'lietuviu');
        
        
         echo lang('privilegijos');
    }

this still translates to english. You see, I need to send emails using a loop. It then loads the needed language, depending on what language is set for user in dabatabe.
#4

[eluser]plain jane[/eluser]
I am not much familiar with the languages in CodeIgniter.

First you load the English language. That may be causing the problem.

For loading the language for Users from database, use the English language as the default if the user has not saved any language.

Thanks,
ci user.
#5

[eluser]SPeed_FANat1c[/eluser]
I will try to describe more crearly what I want to do:

Code:
private function sendEmails($emailai, $liko, $test = FALSE)
    {
      
        //$emailai ne tik emailai, bet ir galioja_iki, pavadinimas, psl_kalba, pav
        foreach ($emailai as $email):
            
        
           //there we load the language by users setting
           $this->load->language('main', $this->getLangByCode($email->psl_kalba));
            
          
          
           $emailas = $email->elpastas;

           //there we translate the the email message
           $message = str_replace("%dienos%", $liko, lang('baigiasiPrenumerataEmailMessage'));
          
           //do additional processing
           $message = str_replace("%prentitle%", lang($email->pav), $message);
          
           //translate the subject
           $subject = lang('baigiasiPrenumerataEmailSubject');
           $from = '[email protected]';
           $from_name = 'Admin';
          
            if ($test) {
                //$this->sendEmail('[email protected]', $email->galioja_iki, $test);
              
                $this->pageData['emailas'] = $emailas;
                $this->pageData['subject'] = $subject;
                $this->pageData['zinute'] = $message;
                
                //there we just print what messages we are prepared to send
                $this->load->view('result2', $this->pageData);
            } else {
                //$this->sendEmail($emailas, $message, $subject, $from, $from_name);
                //atkomentuot kai live, db del apsaugos kad nebutu netycia issiusta
            }
            
            
        endforeach;
        
    }

This code is much bigger, so thats why I earlier made simplified code. As you can see there is a loop, and in each situation it loads the language.

We will run this function to send emails for users who have ending subscription in few days.
#6

[eluser]plain jane[/eluser]
So i guess the problem is when you first time loop through foreach it loads a language, then for another loop it loads another language (according to the setting of the user stored in database). This is causing problem as it has already loaded a language once for the first time it loops through foreach.

Can you use a switch case? Probably that would be lengthy I guess.

Thanks,
ci user
#7

[eluser]SPeed_FANat1c[/eluser]
Quote:So i guess the problem is when you first time loop through foreach it loads a language, then for another loop it loads another language (according to the setting of the user stored in database). This is causing problem as it has already loaded a language once for the first time it loops through foreach.

Similarly. You see there is another function which calls the sendEmails function, and it at first loads some language automatically, because even in the first cycle it doesn't load my specified language.

You see, I call the function this way:

http://mywebsite.com/langCode/Controller/Function-1

And it loads the language which is specified in the url part - langCode

I could call the function few times - lets say one time for russian, one time for english, etc. But we want to make it calling one function for all languages, and it should know itself in what language send the email.

So I need to figure out why it cannot laod another language.
#8

[eluser]plain jane[/eluser]
Sorry,

I cannot help as i have not worked with languages in CodeIgniter.

Thanks,
ci user
#9

[eluser]osci[/eluser]
I believe you can't load the same language file twice, or more.
Look at line 63 of system/core/Lang.php
Code:
if (in_array($langfile, $this->is_loaded, TRUE))
{
   return;
}
#10

[eluser]SPeed_FANat1c[/eluser]
So then I guess there are two ways left:

load the language file using something like $this->laod->file and read it

or

use database for translations.

Btw - there aren't way to unload the language, or is there?




Theme © iAndrew 2016 - Forum software by © MyBB