"Unfortunately" we are ways into adding user defined interface translation functionality implementation at our SVN repository, so I was unable to present a crystal-clear locale cleanup patch, but I hope this will work with you.
There are multiple usability, configuration and API problems fixed in this patch:
- language setup is separated from interface translation (admin/settings/language and admin/build/translate being the new roots)
- there are two distinct permissions now for these two tasks, so translators will not be able to change languages and ruin the site
- the exceptionally messed up locale.inc APIs are clearly cleaned up
Let me elaborate on the third point. If you look at the patch, it has a very big chunk of simply removed cruft at the end. Because locale module has admin functionality in locale.inc, but menu callback require functions to call available without including conditional include files, there were proxy functions *one-by-one* for all forms in locale.module. Bad! Additionally to this, some admin logic was still in locale.module, not moved to locale.inc. And the topping was that some of the forms were named _screen, some where _form, some where _edit and so on. Prefixes were also messed up, some forms directly having _locale prefixed submit callbacks, while some having their submit callbacks proxied through locale module.
Well, MAINTAINERS.txt says I am the maintainer of this mess, so before we go along with adding more features in there (which we are surely going to do BTW :), it was time to clear this situation up once and for all. So what was changed to clean up this situation?
- introduced locale_inc_callback() which is a generic proxy to call when some function needs to be loaded from locale.inc
- identified forms, named them with _form suffix
- identified display screens and concatenated forms and names them with _screen suffix
- identified form functions related to the two separated tasks as explained above and consistently named them with locale_languages and locales_translate prefixed (no underscore at the start)
- grouped functions by their task, added phpdoc comments
- added phpdoc groupings, now that we have the functions grouped
- documented why are some menu items called with drupal_get_form and other are not
I hope this starts a much brighter future for locale.module, having admin and "always required" functionality clearly separated, functions intuitively named. All menu callbacks work with locale_inc_callback now, since we have no URL defined for userspace.
I also fixed some documentation related issues along the way. The .info file still said we are about interface translation, which is not true anymore (we work with nodes and languages in general). Also done a node related fix, putting nodes in a language back to language neutral, if the language is deleted.
Now the above would be nice and cool (quite enough for one big patch itself), but as I said, "unfortunately" we are already way into working on user defined interface text translation. I tried to get as small amount of that in this patch as possible, but what remained was impossible to get out (is spread across all the code), so here it comes. We added the ability to support different 'text domains', with locale module's existing domain being the 'built-in' domain. Modules can define their own domains by implementing hook_locale() and returning a list of domains defined by them for the 'domains' op (we have other ops in the pipe to add there). We are working on adding translation support for aggregator, profile fields, content types and so on with this method (not using t() for it). By reusing what is there in locale module, we can support import and export of those translations, and also get a default textarea based editing for free. We have great plans to provide custom form controls for editing and so on, but this is really not for this patch. What is included in this patch is an extension of the locale module to be able to handle multiple domains for translation and locale module handling the 'built-in' domain directly.
Dries already indicated that 'text domain' is misleading for users, which I kindly agree with. Please come up with something better!
Because the previous language management updates also removed the translation overview screens, this update gets that back into the 'translate interface' section (it is better separated from language setup).
This big update eases (at least my) maintenance work on locale module, so I would be very happy to get this in. A cleanup such as this was very due for locale module now, especially that we are adding more stuff in there very soon (think automated PO import, language block, user specified string translation, etc). Time is tight, so reviews of this patch are very much appreciated! Apply the patch, try out the forms, report problems. Let's get this in!
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | locale_ltr.diff | 1.25 KB | riccardoR |
| #25 | fix_2.txt | 1 byte | Ands |
| #23 | localecleanup6.patch | 78.24 KB | gábor hojtsy |
| #18 | localecleanup5.patch | 76.03 KB | gábor hojtsy |
| #16 | localecleanup4.patch | 74.87 KB | gábor hojtsy |
Comments
Comment #1
meba commentedPatched correctly, no hunks. And no warnings after :-)
The only problem i had is that i can't search strings - the form works, but no strings are found. I commented UPDATE cache in my install, because of some errors, but i don't think it's related.
I also doesn't understand the "text domain". Can you point me to some info? I can't suggest a name without knowing a meaning :-)
Comment #2
meba commentedOh I see what text domain is. Never mind
Comment #3
dries commentedLooks good.
The locale_inc_callback function looks like something which should be part of the menu API ... but I guess we can leave that for another patch.
Comment #4
gábor hojtsy@meba, search works for me! Unless you enable a language and set that to the language used by Drupal, the locale tables will not get populated with strings to search for (and the search for will inform you that no results were found). Do you have records in the locales_source table at least? Did the search say you have no results, or it returns to the same page.
@meba, GNU Gettext has the concept of "text domains" or "translation domains", and I figured we'd rather bring that in, instead of reinventing the wheel here. http://www.gnu.org/software/gettext/manual/gettext.html#Interface-to-get... Different modules would register their own text domains with locale module, so we can provide an interface to translate aggregator categories, content type names, profile field labels and so on. I have a post about this here: http://groups.drupal.org/node/3772
@Dries, you are right, the menu API could probably make use of a generic callback allowing us to call functions in include files. I guess you marked code needs works because of meba's concerns, so I am awaiting more information from meba about search problems.
Comment #5
gábor hojtsyGrabbed latest Drupal HEAD, applied the patch (1 hunk failed). Updated that to reflect the latest menu localization changes.
Tested all forms:
- adding language from predefined list
- adding custom language
- enabling languages, changing default
- configuring language negotiation
- translation overview screen
- translation search with different options (yes it works just as before, don't know what meba sees)
- translation import
- translation template export
- translation export
All forms and screens worked. I fixed one notice bug in PO exporting, which showed up when I had no translation for certain terms and the translation was undefined in the table join.
Unless we know something better then "text domain" for these different translation domains, I would say this is ready to go in. Please review!
Comment #6
gábor hojtsyThe patch!
Comment #7
meba commentedI think text domain is OK, but needs more documentation - examples what is the profit for Drupal. Then it's OK :-)
Comment #8
gábor hojtsy@meba, where do you think that documentation should go? I'll definitely document hook_locale() in contrib/docs, but I don't think this has a place to add in Drupal core. Anyway, domains allow you to add translation for more stuff, let them being exported and such. Watch this: http://hojtsy.hu/drop/dtvideo.mpeg
Comment #9
gábor hojtsyErm, yeah. Some more thinking and I figured we have no documentation for the overview page, where people will face these domains. Added the following as help text for that page:
This hopefully sheds some light on what is that text domain thing. (Yes, I know people will not watch my video, needless to point out :)
Comment #10
meba commentedThat video is awesome, i figured out now what "Text domain" is. And the help text is good i think.
Btw. how many text domains an example Drupal installation will have? What about the table listing languages? I can imagine it will be too wide when 10 text domains are available.
Comment #11
gábor hojtsyMeba, the number of text domains depend on how many can we finish before the code freeze. We are way into trying to come up with a performant solution for "dynamic object translation" (internal name for translation of certain Drupal objects). We are looking at these for that feature in Drupal core:
- (built-in domain already exists)
- aggregator categories and feeds
- user profile labels and categories (categories still need to be factored out to be a separate object, like in aggregator, the current profile module implementation is very translation unfriendly as far as categories go)
- content type names, body labels, etc
- variables AKA site settings (these still require the default values to be factored out to a hook, so you don't need to provide a default value parameter to variable_get() a bazillion of times you use the variable, plus we can easily provide a settings translation interface based on these)
- user defined block titles and contents
At last, we can possibly provide menu items and taxonomy translation, but the above come first, because they are a lot more straightforward (except the two outstanding issues, which should be fixed regardless of our efforts going in or not).
That adds up to at most 8 domains in Drupal core. Any number of domains can show up if people start to update contrib modules. Maybe CCK will go fine under "content types", but others might need to provide their own types. You can have as many languages on the site as you wish also, so I am not sure how that table can scale. Having languages on the vertical axis mirrors the layout of the language setup table, so that seemed logical.
Comment #12
dries commentedFunny. Just like for meba, the video was crucial to help me understand what the text domain is about.
I don't understand the documentation though: "Different text domains allow you to translate parts of Drupal." First question that comes to mind: why is it useful to translate parts of Drupal? Wouldn't you want to translate the entire site?
The fact that you can translate parts of your Drupal site sounds like a side-effect, not the killer feature. Fill in the blank:
Different text domains allow you to ... [complete this] ... by translating one part of your Drupal site at a time.Text domains (like aggregator and user profile) are provided by some modules you use (aggregator and profile module respectively), while the built-in interface domain is always available. What does this help text learn me? I doesn't help me understand what a 'text domain' is.
The key question is: why should people care about the text domain? Why does it need to be a column on the overview page?
(I'm just nitpicking. As mentioned, the patch looks good. It's just that I think we can make it more accessible for the user.)
Comment #13
gábor hojtsyDries, the fundamental difference between what you see and what Drupal 6 users of locale module will see, is that they have node module turned on by default, as well as site settings, so they will start with three domains already listed and being available (I am in the hopes that we can deliver that functionality in time for Drupal 6), making it a lot more obvious that domains group translation by function / area of web site. You needed to see the video to see that you can have more domains, and to see the role of domains in the system. Drupal 6 users with locale module will have three domains enabled by default already.
What about this help text?
Comment #14
gábor hojtsyI need to point out another aspect. Although it is an ideal goal to translate a site 100%, but most of the time it is neither feasible neither even required. While the built-in interface or site settings might not be required to get translated 100%, your user profile details would be. Some translation teams simply skip big admin help texts and leave that in English to concentrate on the user interface of the site. Some site settings will not require translation, even if they are translatable in a usual sense. So different domains might need different levels of completeness, of which the overview provides a good picture of. Because this is site specific, I don't really know how to put hints into the documentation about this.
Comment #15
dries commentedYour last comment explain why text domains are useful.
How about we write something like:
This page provides an overview of interface translation on the site. Drupal groups all translatable strings in so called 'text domains'. Text domains are useful, because you can focus your translation efforts on the text domains you care most about. For example, a translation team could choose not to translate the text domain that includes all the long help texts on the administration pages. Similarly, text domains are useful to ensure that certain aspects of the site are always fully translated.
This is a rough draft and might need refinement. It might not reflect the reality though -- but it looks like that should be the reality. :P Not?
Comment #16
gábor hojtsyDries, you did it! :) That sounds a lot more user friendly compare to my version. Fixed the text to say "grouped into" which is more accurate as far as I know then "grouped in". Updated patch attached.
Comment #17
meba commentedI think this needs little bit clarification of what it does. It allows translating different domains and focus on the main parts, but also it allows internationalization of many aspects of the content - site information, etc. Am i right that this is also important and this is what most of the users will focus on?
Comment #18
gábor hojtsyMeba, "content" is hard to define. Some people prefer to call their menu and taxonomies "interface", because these are used for navigation and such. After a brief discussion with Dries, he added some suggestions, which come up in this patch:
- renamed "text domains" to "text groups" to be super-simple, that also removed confusion of internet domain name support for languages, which is (for us) obviously different, but could have been confusing
- added constants for language directions: LANGUAGE_RTL and LANGUAGE_LTR
- removed debug code from theme function
- renamed "built-in" text group to "default" text group (the translations are definitely not built in)
Dries also pointed out that we should simplify the search screen, which is definitely on the horizon, but would be too much for this patch.
New patch attached! I tested it with all screens: langauge setup, add, edit, configure, translation overview, search, import and export template and translation, and all seem to work.
Comment #19
meba commentedPlease note that locale.inc still has some E_ALL issues, namely:
- line 1153
- line 1126
- line 915
and something is also in:
notice: Trying to get property of non-object in /home/www/drupal/public_html/sestka/modules/locale/locale.module on line 248. (please note that because caching is little bit broken in HEAD, i have commented out UPDATE && INSERT operations in cache.inc
I would produce a patch, but i think it can be incorporated here and honestly i don't know how to make line 1126 E_ALL :-)
Comment #20
gábor hojtsyErm, you cite the following lines:
1153: if (!isset($trans2->lid)) { // no translation in current language
1126: }
915: * @param $op
248: return $form;
I don't see how any of these would be E_ALL problems. How did you come to the conclusion? Care to work with the latest patch, so we can make progress?
Comment #21
gábor hojtsyErm, excuse me, 248 was in locale.module, not in locale.inc. That might make sense to fix:
if ($form['#id'] == 'node-form') {
if (variable_get('language_' . $form['#node']->type, 0)) {
Updated:
if ($form['#id'] == 'node-form') {
if (isset($form['#node']->type) && variable_get('language_' . $form['#node']->type, 0)) {
The others still need clarification.
Comment #22
meba commentedWell, maybe i just used your patch wrong way.
My line 1153: (Near "Now extract formula from stack")
if ($prec[$op]) {
My line 1126:
while (($topop != NULL) && ($prec[$topop] >= $prec[$ctok]) && !(($prec[$topop] == $prec[$ctok]) && $rasc[$topop] && $rasc[$ctok])) {
My line 915:
if ($hdr["Plural-Forms"] && $p = _locale_import_parse_plural_forms($hdr["Plural-Forms"], $file->filename)) {
Comment #23
gábor hojtsyOK, these E_ALL fixes included:
- used isset($topop) in place of $topop != NULL, does the same but is E_ALL compatible
- used if (!empty($varname)) in place of all the if ($varname) stuff used (that was the reason for most if not all E_ALL problems)
Updated patch attached.
Comment #24
dries commentedCommitted to CVS HEAD. Thanks.
Comment #25
Ands commentedComment #26
add1sun commentedhoping he gets banned soon...
Comment #27
riccardoR commentedAdding any predefined languages from admin/settings/language/add always results in languages added with direction 'Right to left'.
See the two occurrences of LANGUAGE_RTL used as default value in the code below, on first and last line.
I think this is a typo.
Patch attached with default direction changed to LANGUAGE_LTR
Comment #28
dries commentedProbably something for Gabor to double check.
Comment #29
gábor hojtsyIndeed, both RTLs are typos, if we don't have direction information from the predefined list, then it means it is LTR, not RTL. The default function parameter should assume the same for consistency. Patch committed, thanks.
Comment #30
(not verified) commentedComment #31
webchickhook_locale() still needs documentation. I added a skeleton placeholder but nothing that remotely resembles actual documentation. Please fix.
Comment #32
webchickhook_translation_link_alter needs documenting as well.Mentioned this over here instead: #141996: Language switcher blockComment #33
webchickComment #34
drewish commentedthe docs for hook_locale were committed at some point: http://api.drupal.org/api/function/hook_locale
Comment #35
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.