Closed (duplicate)
Project:
Views (for Drupal 7)
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
26 May 2008 at 15:28 UTC
Updated:
4 Dec 2009 at 05:41 UTC
From the discussion in http://drupal.org/node/257129#comment-857364 view exports should t'ify translatable strings.
Any way to get this in, soon?
Comments
Comment #1
hass commentedComment #2
merlinofchaos commentedThere isn't a good way for the export system to know which strings should be encased with t() and which should not. I haven't come up with a way to do this, and I've tried.
Comment #3
hass commentedThis doesn't sound good... :-(
Comment #4
merlinofchaos commentedThe best I can think is that there needs to be some smarts; plugins have to mark everything that might be translateable, and then the export system has to acknowledge all of those smarts, which is actually the harder part.
This kind of work needs to be done eventually, anyway, when there is some kind of system that will allow us to do translation of views that are in the database, but currently the system I need does not exist.
Comment #5
merlinofchaos commentedOk, so this is kind of whacky, but I just refactored Views so that it actually knows what's translatable and what's not.
Instead of putting the t() in the export, it actually now runs stuff through t() on load, so you get automatic inline translation of Views; I spoke with Goba and while this is not an ideal solution, it basically works like the menu system does. Unfortunately this means there is no way to automatically extract default view values, but I guess the menu system doesn't do that? i'm not entirely sure how that's supposed to work.
Comment #6
merlinofchaos commentedComment #7
hass commentedIf we are not able to extract the strings with POTX we are not able to translate them with PoEdit and l10n_server and other tools!?
Comment #8
hass commentedI'm happy that you found a possible solution, but I'd like to understand this.
Today you break POTX support... but we end up with translatable strings. Why isn't it possible to use the same logic for the views export and keep the POTX compatibility intact!?
Comment #9
merlinofchaos commentedBefore I delve too deeply into this...how does POTX work for menu strings?
The short answer is: I didn't rewrite the export, because it'll be a fairly significant amount of code to do. I may end up doing that, but it will have an impact on modules and I'm trying to minimize how much this impacts the API (I am in beta, after all, changes to the API are something I try to avoid).
Second, I'm concerned about inconsistent string handling between default (in code) and in database views. If the export has strings run through t(), then they should *not* be translated on the fly but instead should skip translation, and that requires extra code to deal with there, too.
Comment #10
hass commentedHmm.... menu strings are known in modules as long as they are not dynamic or created via UI... menu strings are not yet multilingual except hard coded ones. The POTX parser knows that "title" and "description" in hook_menu are not surrounded by t(), but it extracts the strings into the POT files for translation. I'm not sure if this is possible for views, too. We should ask Gabor... maybe he could comment here, too. I'm not deep enough in view and potx internals, but I hoped to get the strings extracted.
I'm not friend of hard coding something in POTX that's like "if module is views than extract strings like hook_menu's title and description". If we are inconsistent here to the standard way - we end up adding more and more manual exceptions for every module that doesn't work the standard t() way. I don't know what'S the best way here... I only like to be able to translate and I simply don't like to use the Drupal *build-in* interface for this! It sounds like the latest approach is working in this way... if not please correct me.
Comment #11
gábor hojtsyIf you export t() with the views exports, then when you import it, the translated texts will be imported, since the eval()-ed code will be imported, which runs the t(), right? So exporting t() in the code is not an option.
The menu code indeed is recognized by potx because there are simple rules to follow there. Potx parses the module source code and recognizes the title and description fields or menu items based on simple patterns.
Exported views could just as well have these simple patterns defined. But potx has two running modes. One is static code analysis outside of a running Drupal instance. This would not be views compatible at all, unless all views are exported to code at the time of parsing. The drupal runtime integrated potx running mode (when potx is used as a Drupal module) has access to the views API, so it could request exports of views, and parse that code (since potx is better in parsing code then examining database tables for whatnot - although we could look in tables just as well). But in this case, it might make more sense to just add a hook to potx so it could ask other modules to provide a list of translatable strings.
At the end, again, this is all something the locale subsystem in Drupal was *not* designed for, so we are piggy backing a system used for static string translation. However, there is no better way I can offer to Earl without him writing a translation system on his own.
Comment #12
hass commentedWhy not regex'ing all
t()'s out on a import and addt()around all strings on export? This would allow us to reuse the current POTX logic.Comment #13
merlinofchaos commentedGoba: Tell me what I need to do to tell potx about View strings and I'll put it in.
Comment #14
gábor hojtsyAgain, potx is a static code analysis tool, so if you intend to provide the t() wrappers in the exported views for the code analysis, then that's what you can do to let potx know about the strings. Then potx would need to parse the exported views. And the views import should remove the t() wrapper before evaluating the code as Hass suggests. Since potx is a static code analyzer tool, there is no other way but to generate static code for it right now (unless we advance potx to some other direction as well, eg. through some new hooks).
Comment #15
mooffie commentedThere's a solution to this problem in the gettext() world that we can borrow: to have a "no op" version of t(), which would return its argument as-is. We could name it nt(). POTX should be extended to treat it as if it were t() (btw, it already does this for st()).
The python documentation nicknames this "deferred translation", but I don't see this term used elsewhere.
Comment #16
moshe weitzman commentedt() becomes a no op if the current language is english (assuming source string is english) so perhaps this could be faked by Views setting global $language to english or neutral or somesuch before it processes the default views. just a (hackish?) thought.
Comment #17
mooffie commentedBut, Moshe, why a hack? Why not have an official no-op?
Other scripting languages too make use of a no-op version for their t().
Not having a no-op is the reason POTX have quite a bit of "special handling" code.
One may argue: "Having an nt() will confuse programmers, becaue they'll have to stop and think whether to wrap their string in t() or nt()."
This argument isn't valid: They alreay have to think: Whether to wrap their string in t() or not to wrap it at all (e.g. in hook_manu, watchdog, etc.).
Perhaps we should file a 'feature request'. Is somebody here interested enough to open one?
Comment #18
moshe weitzman commentedYou are right Moofie. We could probably get a new function like nt() into D6 since it won't break anything.
Comment #19
merlinofchaos commentedIf Goba were to support it, maybe. But the ramifications of doing so seem quite large. Also then someone would have to write the complex export code I managed to avoid to identify every string marked translatable. =)
Comment #20
hass commented@merlin: Do you think we are able to solve this translation issue for final? If we are made to use the localisation interface we should at least create a textgroup for the view strings, but I don't like this localisation interface solution very much. i18n module have already done this for menu, blocks, taxo, etc.
Comment #21
moshe weitzman commentedWould be nice to do *something* here. I'm not really one to decide what.
Comment #22
merlinofchaos commentedI think the step here is to provide proper integration for potx. In theory it should not be too difficult to write code that looks for a module's default views and scans them for translatable strings and provides them to potx. I'm going to leave that to volunteers, though.
Comment #23
hass commentedWhy are we not able to add t() around the strings in views and maybe parse them away on import, but add them on export to make the files parseable for POTX? This would not require any extra handling in POTX at all.
Comment #24
merlinofchaos commentedBecause then we lose database translation handling.
Comment #25
merlinofchaos commentedClosing this issue in favor of the current issue about creating translation plugins, which will solve this.