Jump to content

RockFrontend now supports translations in LATTE files ?


bernhard
 Share

Recommended Posts

NOTE (2024-10-11): No special syntax needed any more!

I'm so happy about that feature that I think it's worth having a new thread for it! ?

You can now use regular PW translation features directly from within your LATTE files!!

All you need to do is this:

  • make sure you have PW >= 3.0.212
  • add the "latte" extension to ProcessLanguageTranslator's module config (or use the checkbox in RockFrontend's module config if you are using RockMigrations!)
  • add translatable strings to your latte files and make sure to prefix them with either an equal sign or $rf-> or $rockfrontend->

 

Spoiler
<p>{=__('Das ist ein Test')}</p>
<p>{=_x('foo bar', 'context')}</p>
<p>{=_n('Found one item', 'Found multiple items', 1)}</p>
<p>{=_n('Found one item', 'Found multiple items', 2)}</p>

<p>{$rf->_('Das ist ein Test')}</p>
<p>{$rf->_x('foo bar', 'context')}</p>
<p>{$rf->_n('Found one item', 'Found multiple items', 1)}</p>
<p>{$rf->_n('Found one item', 'Found multiple items', 2)}</p>

<p>{$rockfrontend->_('Das ist ein Test')}</p>
<p>{$rockfrontend->_x('foo bar', 'context')}</p>
<p>{$rockfrontend->_n('Found one item', 'Found multiple items', 1)}</p>
<p>{$rockfrontend->_n('Found one item', 'Found multiple items', 2)}</p>

 

 

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

Hey @Sanyaissues thx for liking this post just in the right time!

As of now we don't need any custom syntax any more for translatable strings in Latte files 😎 That's a side-effect of a recent request by @FireWire to make all native PW functions like wire() available in latte files and that also means that __(...) and _n(...) are now natively available in latte files as well!

Just use <h1>{__('This is a translatable headline')}</h1> 🥳

Link to comment
Share on other sites

{\ProcessWire\__text('foo')} works (but it didn't solve my problem hahaha). But guess whose module did the trick

Spoiler
$rm->migrate([
    'fields' => [
        'textlist' => [
            'label' => 'textList',
            'fileMode' => 1,
            'translateFiles' => [
                0 => './pages/home.latte', //Magic!
            ],
            'type' => 'FieldtypeFunctional',
        ],
    ],
(…)

 

 

  • Like 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
 Share

  • Recently Browsing   0 members

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