Jump to content

Independent Var language ?


Recommended Posts

Hi,

I have a Prestashop 1.6 website with 3 languages (english, spanish and italian).

How to use a variable in a specific language independently of the global language ?

I want to change the language of a specific $var only if I click on a button and not with the language selector.

Is it possible ?

Thanks.

Link to comment
Share on other sites

Hi Nemo1,

Thanks for your reply.
I am going to try to be the most understandable :

When I click a flag of the blocklanguages module, the whole contents of the page and the url are translated according to the choice of the language. It is the normal functioning.

What I want :
I need to manage the language of a block independently of the front language.
I have a block in my product pages which contains informations.
The informations are translated in the diverse languages.

Example: the product name

I have a different product name for english, spanish and italian.

I want to display the product name in english even if the front is in another langage.

After that, I display another block of flags near the product name.
This block will affect only the product name.
When I click a flag, the product name is translated according to the choice of the language.

I need a trick like this:
{$product->name|$english|escape:'html':'UTF-8'}
{$product->name|$italian|escape:'html':'UTF-8'}
{$product->name|$spanish|escape:'html':'UTF-8'}

Thanks for any help on this

Link to comment
Share on other sites

Ah! I get it now!

seems complicated. The problem being most of the spots where a name is displayed retrieve it from the database in the specific language only, in the backstanding php file. In the product example, it's productcontroller. So you have to modify that, when the $Product object is retrieved, and get it without passing a language id. This will generate language id-based names and translatable fields, that you can access like $product->name.1 (for id language 1, and so on)

Link to comment
Share on other sites

Hi Nemo1,

This will be very useful for me.
I made the first stage by blocking the var language context ($this->context->language->id) in productcontroller and it works.
The var still use the base language even if I switch the language by the flags. That's a good news but after that, I do not understand how do you call the language id in the product.tpl like you say ($product->name.1)?

Thanks for your help.

Link to comment
Share on other sites

Yes, basically if you use $product = New Product($id_product, false);

It will get a product object with all languages assigned to each translatable field. So, if you assign $product as it is to smarty, you should be able to access the name, say, as an array, as in php it would be $product->name[1] for id_lang =1

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...