I went into string translation to translate the Home link, but nothing happened. There seems to be something wrong in the way i18n_string() is called to fetch the translation.

I just changed that into using t() and it works for me.

Comments

badrange’s picture

This one is made against today's 7.x-2.x

badrange’s picture

This one is made against 7.x-2.7

Babou’s picture

I would add that it only happens if the variable easy_breadcrumb-home_segment_title is defined by the admin. If this is the case, then it is not translatable at all.

So even if you simply save the admin form without changing its default Home value, then, it's no longer translated. Actually, the simple fact that the variable exists voids the translation.

It never goes through the t() function but instead i18n_string (which I didn't investigate that much).

As suggested above, simply changing i18n_string() into t() solves the problem.

I still submit a patch as I don't think it is necessary to check if i18n_string exists in order to run the t() function.

bart.hanssens’s picture

Issue tags: +release1.1

Added tag

bart.hanssens’s picture

Issue tags: -release1.1

sorry, wrong queue, removing tag

greg boggs’s picture

Status: Active » Needs review

Patch looks good to me.

sonemonu’s picture

Assigned: Unassigned » sonemonu
Status: Needs review » Closed (works as designed)

Hi Guys, I'm back. Thank you so much for your feedbacks about the module!

I think using the "t" function in the approach suggested in the patch is againts a "good practice" the Drupal's official documentation states here: https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/7

You should never use t() to translate variables, such as calling
t($text);
, unless the text that the variable holds has been passed through t() elsewhere (e.g., $text is one of several translated literal strings in an array). It is especially important never to call
t($user_text);
, where $user_text is some text that a user entered - doing that can lead to cross-site scripting and other security problems...

Question: Just to be sure, have you tried intalling and enabling the module 'i18n'?

sonemonu’s picture

Please try installing and enabling the 'i18n' module, and let us know. Thanks.

Babou’s picture

i18n is installed and enabled and it doesn't work at all for me unless I use the t() function.

I will try to debug it further when I will have some time.

badrange’s picture

i18n is also installed here

sonemonu’s picture

Issue summary: View changes
Status: Closed (works as designed) » Closed (fixed)

Corrected in 7.x-2.9. Used the function "t" (previous sanitization of the user's text-input through the "check_plain" function).

The 'i18n_string' function do not works as expected and I can't find any documentation regarding its proper usage.

greg boggs’s picture

Status: Closed (fixed) » Needs work
greg boggs’s picture

Translating Variables

"You should never use t() to translate variables". Instead, you want to provide metadata about the variable to indiciate that it can be localized. in hook_variable_info();

See here:
http://drupal.stackexchange.com/questions/9362/is-it-always-bad-to-pass-...
http://api.drupalhelp.net/api/variable/variable.api.php/function/hook_va...
https://drupal.org/node/1113374

The module used to translate variables is called variable_translation which is a submodule of i18n.

nonsie’s picture

Here's a possible approach using hook_variable_info(). You will need to enable Variable translation (part of i18n), enable front page title as translatable variable and then translate it via admin/config/system/variable/group/easy_breadcrumb.

greg boggs’s picture

I have tested this patch with locale, variable_realm, variable_store, i18n_variable, variable, i18n and it works as expected. So, I've committed it to the 7.x.2.x-dev branch.

In case someone comes across this issue and doesn't know how to use the translation modules, to test this you must enable the language you want to translate into, then enable URL for language selection and language switcher block. Next you must set the value you wish for the home variable and finally set the translations via the variable UI interface. When you switch languages, the Home crumb should switch languages.

greg boggs’s picture

Assigned: sonemonu » greg boggs
Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

soumyadas’s picture

StatusFileSize
new854 bytes
greg boggs’s picture

Thanks for the patch ssdas. A working, tested, and well implemented patch is already available in #14. It has not yet been included in the latest stable release.

The main difference between your patch and the one we used is that your patch uses the t() function on user content stored in a Drupal variable.

  • Commit 7ddd286 on master, 7.x-2.x:
    Issue #2071747 by nonsie: fix variable translations of home link to not...
greg boggs’s picture

Roger,

You're doing an excellent job on easy breadcrumb! Thanks for getting the tags merged into the 2x branch and jumping on the reports so quickly.

In this commit: http://drupalcode.org/project/easy_breadcrumb.git/commit/2af9cad, you removed the correct variable translations code that Nonsie supplied with the above patch in #14.

Do you need me to re-roll the patch against the latest 2x branch so you can reapply the variable translations code?

sonemonu’s picture

Hey Greg,

Yes, I removed that file because of I did not found any code referencing it (this is probably a mistake of mine, since I do not know how the variables translations feature does works). I've some questions about this, how is that supposed to work? I see you implemented a hook in that file, but such hook should not be referenced by the .module file?

Thanks,
Roger Padilla

greg boggs’s picture

Translation of variables is a tough issue. I've had to get help to understand it myself.

See the change from here: http://cgit.drupalcode.org/easy_breadcrumb/commit/?id=7ddd286

Once you set the metadata on the variable to make it translatable, you no longer need custom translation logic in the module file because the Drupal variable translation module uses the metadata on the variable to make the variable available for translation.

~G

sonemonu’s picture

Gregg,

OK, thanks. Just to be sure, then it is not necessary to include/reference the file 'easy_breadcrumb.variable.inc' from the .module or .info? or is it auto-referenced by Drupal?

Roger

greg boggs’s picture

You're right, I believe the inc file will need to be included. It looks like the hooks could also live in the .module file according to http://cgit.drupalcode.org/variable/tree/README.txt?id=7.x-2.5

greg boggs’s picture

Assigned: greg boggs » Unassigned
Status: Closed (fixed) » Needs work

This one seems to have gotten lost in the shuffle. It needs a reroll against the latest release.

Xrobak’s picture

I've create easy_breadcrumb.variable.inc in module root folder, then open admin/config/regional/i18n/variable/ and turned on ability to translate "Title for the front page segment in the breadcrumb". Then I go to admin/config/user-interface/easy-breadcrumb/ and there is nothing to translate. Also tried admin/config/system/variable/group/easy_breadcrumb but there is no Easy Breadcrumb block at all.

So, what I did wrong? I need to translate my custom text for Easy Breadcrumb but can't do it :( I'm using easy_breadcrumb-7.x-2.12 and drupal 7.39

greg boggs’s picture

Easy Breadcrumb is currently using t() for translation. So, once you load a page with the crumb on it, you should be able to find it in the translation interface as a string rather than a variable.

Xrobak’s picture

Greg Boggs, thank you. Now I found it and have to say some things:
1. Breadcrumb title has a string path with that page where you was while doing changes to title in admin/config/user-interface/easy-breadcrumb/. So this make me confused why this breadcrumb title stored in some page path and not home page. So, looks like it better go to website home page and after setup breadcrumb title in overlay.
2. If you use few languages and english is not your primary language, you must setup title in admin/config/user-interface/easy-breadcrumb/ in english language and then translate it as string. In other way you can't translate breadcrumb title to english. I think you need add this information to readme.txt. Thank you!

greg boggs’s picture

Closing this as works well enough with t();

greg boggs’s picture

Status: Needs work » Closed (works as designed)