Among the various possible approaches under discussion for object translation in core, see http://groups.drupal.org/node/18735 for a complete list:

1. Each item that has translatable properties declares them on its fields ('translatable' => TRUE).

2. Locale module creates and maintains a parallel table for each table that includes translatable properties. E.g. if myobject has three translatable fields ('name', 'title', 'description'), Locale would create a table 'locale_myobject' and assign it the fields name, title, and description plus the primary key field or fields plus a language field.

3. In the db_select object, we add a method, $query->translate(). This would iterate through all existing tables, consult the schema, and (a) if fields have already been added, join on their locale_x table and load the translated version of the fields or (b) if it's a query for all fields, fetch all translated fields. $query->translate() could accept an array of languages, in which case there would be a join per language.

4. Add a method to db_delete to run any deletions also on locale_x tables.

CommentFileSizeAuthor
#3 locale_textgroup_schema.patch8.3 KBJose Reyero
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jose Reyero’s picture

This looks like a great idea to me. Pushing the concept a bit further I'd add two options for the schema:

- 'localizable' => TRUE, for fields. That would replace the one mentioned above and means it is a string that may be localized.
- 'translatable' => TRUE, for tables. This would mean this table stores object with language attribute, and such objects may be translated as a whole (create another language version of them which will be somehow linked to this one)

In addition to these two, there's the language field (which we should make a 'reserved' name), and will mean this table stores objects with a language, and in turn, if running any 'language selection' option, the query conditions can be added in automatically. I.e. if you just want to see content only for English language, any query for selecting lists of objects will add the condition alias.language IN ('en', ''), thus we'll see only English or language neutral stuff.

While a 'translatable' table will have a linked table, which can be created automatically if translation module enabled like.

trid, int, translation set id
language
id, int numeric primary index in the linked table
nedjo’s picture

Status: Active » Postponed

#367595: Translatable fields may render this approach unneeded--or maybe not, if we're left with properties that won't be converted into fields.

So postponed until #367595: Translatable fields takes shape.

Jose Reyero’s picture

Status: Postponed » Needs review
FileSize
8.3 KB

This is a rough draft of what this could be, waiting for the locale API to be improved...

The idea: you just need to ad 'localize' => TRUE to the fields to be localizable, locale handles the rest
* It adds a 'This field is localizable' to fieds in forms. First you need to add the '#schema_table' property for CRUD forms
* Hooks into object updating (which ideally would be done all through drupal_write_record or similar), and updates strings

The trickiest part is to do all the 'textgroup - table - field - string_id' mapping, that is sorted out in this patch.

For localizing objects later (once we have the strings handled and translating) we could use something similar to #141461: Object translation option #1: locale system, optimization strategies

There are a pair hacks for it to work with content types (they don't use drupal_write_record).

*The issue with this approach to be workable is that we need some object api (write, update, load, etc...) with some hooks so we can plug in when any object is created/updated/deleted/lodaded without implementing a thousand hooks. So maybe we should give one more push to

So patches this needs:
#361597: CRUD API for locale source and locale target strings
#365899: API methods for schema-based load and delete operations

Status: Needs review » Needs work

The last submitted patch failed testing.

plach’s picture

Version: 7.x-dev » 8.x-dev

I am afraid we will have to reconsider for D8 :(

jhedstrom’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.