Jump to content

Display a string of text only in a certain language.


USB83

Recommended Posts

Hello,

 

For a shop offered in two languages, I'm looking for a way to include a string of text in my template (default-bootstrap) but i only want that string to be displayed for visitors browsing the website in english.

 

Here the html structure of the string i want to include :

<div id="en-instructions">Lorem ipsum dolor sit amet, <a href=#">consectetur adipiscing elit</a></div>

Can anyone help me with this ?

 

Thanks a lot !

Link to comment
Share on other sites

That is simple, may be more simple than you thought.

At very first, make it translatable string like this:

<div id="en-instructions">{l s='Lorem ipsum dolor sit amet,'} <a href="#">{l s='consectetur adipiscing elit'}</a></div> 

Just go to your Translation panel in dashboard and replace your string with space in language for what you don't want to display it.

Link to comment
Share on other sites

Hello,

 

Yes i thought about doing it that way (that's actually how i've been doing it so far) but i wanted to do it the right way, with an if statement in the template for example.

 

Because now, even though in the browser view, the message is shown only when the website is set to english, i still have this in the source code with the other language :

<div id="en-instructions">  
   <a href="http://random_url.com" target="_blank"> </a>
</div>

It's not a big deal but i'm learning php and theming so i'm looking for a solution to do it the right way and to learn at the same time  :) 
 

Thanks a lot for your answer and your time anyway  ;) !

Link to comment
Share on other sites

That is simple, may be more simple than you thought.

At very first, make it translatable string like this:

<div id="en-instructions">{l s='Lorem ipsum dolor sit amet,'} <a href="#">{l s='consectetur adipiscing elit'}</a></div> 

Just go to your Translation panel in dashboard and replace your string with space in language for what you don't want to display it.

i had the same problem but thanks to you i just solved it.

Link to comment
Share on other sites

While the above solutions will work, translating something with an empty string feels like a 'hack', of sorts. It seems like a cleaner solution would be to not show the string altogether, via e.g.

{if ($lang_iso == "en")}{l s='your string'}{/if}

Not saying the other solutions are at all wrong, but this more closely reflects the actual behaviour you seemed to want.

Edited by Apium (see edit history)
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...