Jump to content

Multilang Addon


dorzki

Recommended Posts

Hello,

I'm trying to add support for multiple languages.

 

I have a function which runs when InvoicePaid hooks runs and sends an SMS notification to a certain phone number.

 

I've created two language files under lang directory on my addon directory - hebrew and english.

 

in English the file content is:

 

<?php

$_ADDONLANG['sms_message'] = 'Test';

 

But i can't seem to get the language in the function, i've tried $LANG and even Lang::trans('sms_message') and all i get is null.

 

Would love to get help as the developer documentation sucks.

Link to comment
Share on other sites

user language can be detected using a session variable:

$userLang = $_SESSION['Language'];
// or the following
global $CONFIG;
$userLang = $CONFIG['Language'];

 

inside module functions the it's simple to use your translation

<?php

function addonmodule_output($vars){
   $LANG = $vars['_lang'];

   echo $LANG['sms_message'];
}

Link to comment
Share on other sites

  • 2 years later...
9 hours ago, Jumm said:

What need  to pass variable to lang?

I have in  english.php


$_ADDONLANG['sms_message $variable'];

 

How can I get it in the hook?

you would need to do it by adding a key in the translation phrase as:

$_ADDONLANG['sms_message'] = "Hello :name";

then when you are about to display/use that phrase, you should replace that key with the appropriate value:

function addonmodule_output($vars)
{
    $_lang = $vars['_lang']; // an array of the currently loaded language variables from addon module

	$helloMessage = str_replace(":name", "John", $_lang['sms_message']);

	echo $helloMessage; // Hello John
}

that's how it works, and you can define as many different keys as you would need

Link to comment
Share on other sites

11 minutes ago, Jumm said:

Thank you  for answer

whmcs functional doesn't have better option than php function str_replace?

well, for WHMCS main language I would use the following:
 

Lang::trans('sms_message', array('name' => "John"))

and that support to work as they use Laravel!

but as you want to use Addon language translation and as all the phrases has been already assigned into an array ($vars['_lang']) and since WHMCS doesn't have the same functionality above, the only option is to use "str_replace" which will give you the same result.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated