It is not recommended to use t() for translating dynamic data. This way is quite insecure and not flexible.
For now it looks like this (title Article %node:title (%node:comment-count)):

It will be better, if we do t() before token replacement, but still not so good for maintenance.
Inspired by my first code contribution, I suggest a concept patch with “path_breadcrumbs_i18n” module. It uses i18n_string Framework for creation, updating and deleting i18n strings.
Important notes:
- To interact with main module there is an alter hook 'path_breadcrumbs_build_breadcrumbs', but can be used another way.
- To make i18n “Translate” tab visible I have created MENU_DEFAULT_LOCAL_TASK item (temporary solution).
Status of this patch:
Concept, needs review.
Further work:
- UI improvement for i18n page
- Rethinking 'translate' property
- Appropriate translation of “Home” link (i18n_variable)
- Testing, of course
How to test:
Apply a patch, enable “path_breadcrumbs_i18n” module, go to page admin/structure/path-breadcrumbs/edit/%/translate for any path breadcrumb with translatable flag set to 1.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | path_breadcrumbs-i18n-1645360-10.patch | 13.12 KB | kalabro |
| #11 | interdiff.txt | 567 bytes | kalabro |
| #9 | path_breadcrumbs-i18n-1645360-9.patch | 12.72 KB | kalabro |
| #9 | 2012-07-17_13-45-07.png | 20.28 KB | kalabro |
| #5 | path-breadcrumbs-i18n-patch-5.patch | 8.64 KB | spleshka |
Comments
Comment #1
spleshkaWow, that is so cool, thank you indeed! I have made a quick code review and I really liked it. I will test this module as soon as I have some free time. Hope that it will be today =)
Comment #2
spleshkaYou know, I don't like only one thing: now breadcrumbs will be translatable only if user enable i18n. I'm not sure that this is a good idea. Moreover, what will happen with current translations for breadcrumbs? I use translations for breadcrumbs on one project. If I just update to a new version they will gone and users will see untranslated content. We should think about migration.
Comment #3
kalabroIn defense of i18n_string
Yes, this solution has dependence i18n_string. Any complex multilingual Drupal 7 site has to use i18n package for menus, blocks, views, etc. i18n_string provides very clear infrastructure for storing multilingual data. I see i18n Views and i18n Rules uses i18n_string successfuly. Entity API began to provide i18n stuff for entities and this tendency is growing for entity modules. I believe i18n_string is the optimal solution for Drupal 7. For one-language sites this module can be disabled and some help message about how to turn on translation can be shown.
On the other hand, we can just
t()them all — http://hojtsy.hu/blog/2011-may-19/drupals-multilingual-problem-why-t-wro....Migration
It can be done, I think. For example, we can go through all path_breadcrumbs objects in hook_update or migration module and prepopulate i18n strings with old
t()values.But I'm not sure if it is really needed.
Comment #4
spleshkaI didn't say that i18n in bad solution. It is great solution! But I am worry about simple multilanguage sites. But I agree with you - we could make this module like Views: translations only with i18n.
Migration
I insists on migration. I showed you an example with my project: if I update to a new module version all my translations will disapear and I will have to create new translations. My project contains 84 breadcrumb navigations and ~20-30k visitors daily. I think that they are won't be happy to see unknown language on the screen.
Comment #5
spleshkaAfter last module updates I refactored your patch so now it is satisfies current requirements. Patch is attached.
Comment #6
spleshkaI really don't like this code:
I think that it is better to provide hook_path_breadcrumbs_save() and hook_path_breadcrumbs_delete() than try to change forms behavior. Your variant is not module-friendly: other modules will not get translate features if they will save/update/delete path breadcrumbs.
Now we got next todo list:
Comment #7
kalabroReally happy you suggested to create API!
I think we can provide hooks first (issue #1648260: Provide API for other modules) and than continue work with i18n.
Thanks for review. I will work on it tonight :)
Comment #8
spleshkaIt is a really good idea to implement hooks first. I would be so happy to review patch with it :)
Comment #9
kalabroMain changes since last patch:
Comment #10
kalabroComment #11
kalabroOops, forgot to remove the old piece of code :)
Comment #12
spleshkaOh, I'm sorry that you had to wait so long. I'm finally got some time to review this patch.
I found there some bugs, fixed them and commited it to 7.x-3.x. I hope that new 3.x branch will bring to Path breadcrumbs new features (like full token support) and performance improvements.
Your patch fix my fixes was commited at 26b8bbf.
@kalabro, thank you so much for your time. I am really appreciate that.
Comment #13
kalabroThanks, @Spleshka!
Some notes:
To translate Home link title (if you use option “Prepend Home link to the breadcrumb”) you should:
- enable Variable translation module (i18n_variable) from Internationalization package
- make variable “Home link title” multilingual on page
admin/config/regional/i18n/variable- go to Path Breadcrumbs settings page (
admin/structure/path-breadcrumbs/settingsand set variable value for each language.Comment #14
spleshkaI know, we should write documentation about it.