As a followup from #1445682: Source Plugin: i18n Strings UI

Only certain i18n objects are supported yet in i18n strings source.
We should add a fallback list to support the remaining i18n strings where object support doesn't work.

Related is also the separate locale support of plain old t() calls in code. Possibly a separate issue.

CommentFileSizeAuthor
#11 2006422-11.patch5.33 KBleksat
#9 2006422-9.patch1.64 KBleksat
#6 2006422-6.patch1.47 KBleksat

Comments

miro_dietiker’s picture

owen barton’s picture

I have a need for this - specifically I am using the i18n_panels sandbox (and related patches), but display titles come through (I think) as simple strings with no wrapper class and since tmgmt doesn't handle them fail due to "zero words". I spent a bit of time digging through i18n_string, i18n_panels and tmgmt trying to work out where/how to best add this, but didn't find anything I felt was the right place.

@miro_dietiker - if you are able to outline what needs to happen here, I may be able to implement this. Alternatively, if you have a patch, I am happy to help test.

berdir’s picture

Hm.

What we have now is:

tmgmt_locale.module: Hardcoded to the default textgroup.
tmgmt_i18n_string.module: Only considers textgroups that are defined as i18n objects.

So we are missing the things that fall between the two.

It might be easier to extend tmgmt_locale to support those, I'm not 100% sure right now. Depends on wether these strings still have some i18n related information somewhere that we need.

Either one of those two needs to provide a separate source type that contains a query that is similar to tmgmt_i18n_string_get_strings()/TMGMTLocaleSourceUIController::getStrings() but does the opposite. Exclude all known textgroups from i18n objects and default too.

leksat’s picture

Issue summary: View changes

To quickly allow translation of other textgroups, I used the following code:

/**
 * Implements hook_tmgmt_source_plugin_info_alter();
 */
function MY_MODULE_tmgmt_source_plugin_info_alter(&$info) {
  if (isset($info['locale']['ui controller class'])) {

    // TMGMT Locale plugin only supports the "default" textgroup. Add other
    // textgroups as well.
    $textgroups = db_Select('locales_source', 'ls')
      ->fields('ls', array('textgroup'))
      ->distinct()
      ->execute()
      ->fetchCol();
    foreach ($textgroups as $textgroup) {
      if (!isset($info['locale']['item types'][$textgroup])) {
        $info['locale']['item types'][$textgroup] = t('Locale (@textgroup)', array('@textgroup' => $textgroup));
      }
    }
  }
}

Is this a correct approach?

leksat’s picture

My suggestion from #4 is not correct.

Currently we have the following code to deal with i18n_panels and webform_localization modules:

/**
 * Implements hook_tmgmt_source_plugin_info_alter();
 */
function custom_tmgmt_source_plugin_info_alter(&$info) {

  // The i18n_module describes "pane_configuration" and
  // "display_configuration" i18n objects, but does not provide an ability to 
  // load them.
  /* @see i18n_panels_i18n_object_info() */
  // So, when we try to create a job item, the i18n object is NULL, and TMGMT
  // fails with an error.
  // To resolve this, disable "Pane Configuration" and "Display Configuration" 
  // tabs (handled by the tmgmt_i18n_string module), and create "Panels" tab 
  // (handled by the tmgmt_locale module) which will allow to translate any
  // string belonging to the "panels" textgroup.
  unset($info['i18n_string']['item types']['pane_configuration']);
  unset($info['i18n_string']['item types']['display_configuration']);
  $info['locale']['item types']['panels'] = t('Panels');

  // Allow the tmgmt_locale to translate the "webform" textgroup.
  $info['locale']['item types']['webform'] = t('Webform');
}

Can't we put this code in the TMGMT module?

leksat’s picture

Status: Active » Needs review
StatusFileSize
new1.47 KB

We've been using the code from #5 for quite some time on 4 production projects and it works just great.
Converted this to a patch.
I think this approach is the only way to fix the situation for D7.

berdir’s picture

Status: Needs review » Needs work

Fine with adding workarounds if that helps.

However, we don't need to implement our own hook, especially not in the base module :)

Just put this logic directly into tmgmt_i18n_string:)

berdir’s picture

Status: Needs work » Postponed (maintainer needs more info)

See also #2639852: TMGMT API does not play nice with i18nviews and i18n_panels. According to the patch author there, that patch should fix this too and seems less specific. Can you test the patch and confirm that it works so we can commit it?

leksat’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.64 KB

Checked the patch from #2639852: TMGMT API does not play nice with i18nviews and i18n_panels. It makes sense.

And I finally realized what the current issue for :)

Attached patch makes tmgmt_locale handle all text groups that are not handled by the tmgmt_i18n_string (for example, webform).

leksat’s picture

leksat’s picture

StatusFileSize
new5.33 KB

One thing I did not take into account in #9 patch is that strings coming from i18n_string can have the source language different from "en".

charlesj’s picture

#6 works for me.
D7.41 / PHP 5.5 / MySQL 5.6