Sign in to follow this  
Hurme

Translated strings not showing up in frontend

Recommended Posts

I've added language support to a website. Language switching works and fields that have content in the second language show up correctly.  But none of the translated strings work.

As I've understood, the most simple way to add translated string is:

<?php
echo __('This will be translated');
?>

When I go to the second language in backend, it correctly finds this string in the file it was used, and I can write the translation below it.

How ever in frontend nothing ever happens, and the website always shows "This will be translated" instead of the translation itself.

Also a curious note, backend will find translated strings from template files, but if I add string to a file starting with underscore, _main.php for an example, it's unable to find those translations even when I write the file path manually.

Am I missing something here? Where could I start looking for answers?

I've read through the language docs and browsing old topics, but I haven't been able to solve this problem on my own.

Share this post


Link to post
Share on other sites

Hello @Hurme,

if your string tranlastion is in a template file, it should work like this. If your string is in a included or prepended file (f. e. _main.php), this doesn't work in my experience. For this you could use text domains inside your string translations. I used to have a single included file (translations.php) in which I collected all string translations and used a text domain to point all string translations to this included file:

Anywhere:

echo __("This will be translated", "/site/templates/includes/translations.php");

In translations.php

__("This will be translated");

You could save the text domain into a variable so you don't have to write the whole path every time. 

Nowadays I'm thinking about using the ProModule Functional Fields for string translations only, because it gives you more freedom. For example if the original string translation needs to be changed, you have to edit it in your template and enter the translations again in the back-end, because they have lost the connection. With Functional Fields a editor can edit the translations and the original string without losing the connection. If you have the ProFields, it is worth checking out Functional Fields. 😉

 

2 hours ago, Hurme said:

Also a curious note, backend will find translated strings from template files, but if I add string to a file starting with underscore, _main.php for an example, it's unable to find those translations even when I write the file path manually.

You have to add those files with string translations manually via the "Translate files" button. You should see there every file with string translations, either in the "site" or "wire" folder.

Regards, Andreas

  • Like 3

Share this post


Link to post
Share on other sites

Hi,

Thanks for the answer! I'll try this later this week, once I continue working on the site. I do have ProFields and I understand what you mean. It might very well be worth doing it like you suggested.

  • Like 1

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.