Forum

Thread tagged as: Question, Problem

[Multi-lingual site] Translations of short texts in txt file

Hi,

What is the best way to handle translations that are not necessarily included in the admin through a localised region for instance. I'm thinking about short words that I'm unlikely to change and could be maintained in a text file.

Does Perch provides a helper that I could use in the template to replace the current hard coded text? Based on the current language, it would pick-up the value.

Something like what is used for the translations of the admin

{
    "lang": "en-gb",
    "Pages": "Pages",
    "Manage Content": "Manage Content",
    "Shared": "Shared",
    "Perch": "Perch",
    "Settings": "Settings"
}

Cheers, Robin

Robin Pick

Robin Pick 5 points

  • 7 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

You can use Perch to edit any text file - it doesn't need to be an HTML page.

So if you wanted to store things as a text file, or even JSON or XML, as long as PHP can parse that file you can use Perch to edit the content just by adding a Perch Region as normal and then creating a template for the output.

Thanks for your reply.

Currently, my templates become a bit messy because I'm using <perch:if> to check the current language and to display a given translated text:

<perch:if id="current_language" match="eq" value="fr">
       thèmes : 
<perch:else />
       themes:
</perch:if>

I use this approach for all the short texts. I could create <perch:content> for these texts but I feel this will decrease readability when editing the content – as there might be many of these depending on the page.

Would you have any thoughts on this? There might be a nifty perch helper I could use.

I was thinking using a plain text file to maintain these sort of translations but I have to say I don't know how to approach the problem: how could I output a translation based on the current language in the template without having to use the <perch:if>?

Many thanks, Robin

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think we have a good solution for you.