Jump to content

How to get active language?


Recommended Posts

Hi Chris,

I thought you had retired - are you planning on making the greatest comeback since Lazarus ? 🙂

37 minutes ago, ChrisTERiS said:

is there any build-in function to get the active language to use it in a hook code? eg If is a visitor to return the site's default language, if it's a logon user to return the user's language.

possibly depends on the hook and what you have access to, but I would have thought that you could use $vars['language'] and return the current CA language value in lowercase... there's the ActiveLocale array too, but the language value in that should be the same as 'language'.

Link to comment
Share on other sites

@brian!

I'm retired !!! 🙂 🙂 (but still waiting to get my pension on hands)

But coding is like virus... can't stay inactive for long time. So from time to time I'm trying to add some extra features in my mods. Today I decided to make Legal Agreements multilingual. It got me just a couple of hours. Was really easy. But now I've to deal with the difficult (??) part. To know the active language, and show the correct articles.

Maybe the $_SESSION keeps this data. I found a smarty variable $activeLocale that also holds the language, but this works only in tpl files, while I want to use it in my hook file.

Happy to see you again here, active and helpful as always 🙂

Edited: $_SESSION["Language"] works at least in the place that I want. Have tried it before but didn't worked as I didn't noticed that is Language and not language 😞

Edited by ChrisTERiS
Typo
Link to comment
Share on other sites

6 minutes ago, ChrisTERiS said:

Today I decided to make Legal Agreements multilingual. It got me just a couple of hours. Was really easy. But now I've to deal with the difficult (??) part. To know the active language, and show the correct articles.

how are you creating the multilingual text ? if you using addon language files, WHMCS should use the correct language file without any intervention...

https://developers.whmcs.com/addon-modules/multi-language/

17 minutes ago, ChrisTERiS said:

Maybe the $_SESSION keeps this data.

I could be wrong, but I think the language is only set in the session on a language change - though i'm probably thinking of CA hooks....

hopefully, if you're following the addon language method above, you might not need to work out the user's language.

Link to comment
Share on other sites

1.- I added a field in agreements table to hold the language. Then I query the agreements according to the active language.

2.- Yes, it's true. The $_SESSION["Language"] is empty if the non logon visitor does not changes language from the menu. But this was easy. If it's empty I set in the query the default (site) language.

// Query Database for Agreements
if (empty($_SESSION["Language"]))
{
	$ct_agreements = Capsule::table('mod_legalterms_articles')
					->where('language','english')
					->orderBy('displayorder','asc')
					->get();
} else {
	$ct_agreements = Capsule::table('mod_legalterms_articles')
					->where('language',''.$_SESSION["Language"].'')
					->orderBy('displayorder','asc')
					->get();
}

The above code has hand-coded english as default language, but I'm in research to find the correct variable for it 🙂

image.thumb.png.b44bd1b361a41d8c097620399cb97f4f.png

Edited by ChrisTERiS
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