Jump to content

translate hardcoded text


vxda
 Share

Recommended Posts

Hi guys, is there a way to translate hardcoded html text for example:

 

<div class="tabs">
<a href="#">Tab name in some language</a>
<a href="#">Tab name in some language2</a>
<a href="#">Tab name in some language3</a>
</div>

i know that we can do something like

<?php

if ($lang == 'en') {
echo "<a href="#">Tab name in English languge</a>"
}
if ($lang == "other ") {
echo "<a href="#">Tab name in other languge</a>"
}

I was thinking about module of some kind working like "Process Language Translator" or

in code u use variable tags like : {lang-TabNameInSomeLanguage}

<div class="tabs">
<a href="#">{lang-TabNameOne}</a>
<a href="#">{lang-TabNameTwo}</a>
<a href="#">{lang-TabNameThree}</a>
</div>

in Admin some sort of table like this with translation for each language we create.

Varialbe                              ENG                       DEU                                POL

TabNameThree         this is tab one            dies ist einer Tab           To jest jedna zakladka

Or there is totaly other easy way that im not aware of ?

Cheers

Paul.

Link to comment
Share on other sites

I'm a bit confused by the title of the thread... so, you don't want it hardcoded right?

What you seem to be asking is very easy with the new multi-language fields http://processwire.com/api/multi-language-support/multi-language-fields/

This post from Phillip and subsequent answers might also be useful for you http://processwire.com/talk/topic/5518-multi-language-site/?p=53784

Link to comment
Share on other sites

There is no reason that you have to have any hard coded text at all really - if you are creating tabs, for instance, you can have the tab headers as fields, either generated by the page that is supplying the pane content or, if you are using them more globally, from some sort of global settings page. Then you can use multi-language fields quite happily.

  • Like 1
Link to comment
Share on other sites

One thing is not working for me dunno why, in API docs i see this should work:

$out = __("It's time for you \nto get to the party.");  // good 

but it seams not, here is my code:

<h2><?php echo __('Safe \nplastic surgery') ?></h2>

Any tips ?

Link to comment
Share on other sites

You need double quotes "".

Also I guess the new line is visible when translating the string in the Pw admin.

To get a new line in html, you need the br tag:

<h2><?php echo nl2br(__("first line\nsecond line"));?></h2>
  • Like 2
Link to comment
Share on other sites

  • 1 month later...
<h2><?php echo __('Safe \nplastic surgery') ?></h2>

Cannot reproduce this. Example works in Language Translator/ Language Translator Plus

You can use both (Single and Double quotes) look here: wire/modules/LanguageSupport/LanguageParser.php  function parseFile($file)

It doesn't work, if you have more than one translatable string in one line ,like

<h2><?php echo __('Safe \nplastic surgery') ?></h2><p><?php echo __('2nd string') ?></p>

The second string will not appear in the language translator. Its a bug. Maybe Ryan could help.

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
 Share

  • Recently Browsing   0 members

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