Currently, if one needs to change character mappings or add language-specific variants, the mapping files in the translation module must be patched. This is bad practice because it makes updating the module very difficult.

I propose that a hook be added that will allow modules to alter character mappings.

CommentFileSizeAuthor
#1 alter-mappings-1943290-1.patch835 bytesjtsnow

Comments

jtsnow’s picture

StatusFileSize
new835 bytes

I've attached a patch that would allow modules to alter character mappings.

It works by allowing modules to supply an alternate mapping file. Here is an example of how I am using it:

/**
 * Implements hook_transliteration_map_alter().
 */
function my_module_transliteration_file_alter(&$file, $context) {
  if ($context['filename'] == 'x21') {
    $file = drupal_get_path('module', 'my_module') . '/transliteration/' . $context['filename'] . '.php';
  }
}

Modules can also use it to supply a language-specific file for variants without duplicating the code for the base mapping.

/**
 * Implements hook_transliteration_map_alter().
 */
function my_module_transliteration_file_alter(&$file, $context) {
  if ($context['filename'] == 'x00' && $context['langcode'] == 'da') {
    $file = drupal_get_path('module', 'my_module') . '/transliteration/' . $context['filename'] . '-da.php';
  }
}
jtsnow’s picture

Status: Active » Needs review
amateescu’s picture

Status: Needs review » Postponed

I think this should be postponed to 7.x-4.x, which will be a backport of the codebase from D8 core that already includes this hook.

BeRGB’s picture

Issue summary: View changes

Definitely it would be useful, I have problem with serbian characters like
$variant['sr'] = array(
0x10 => 'Dj',
0x11 => 'dj',
);

I have to add directly in data file, probably I will override on next update :)

michaelpetri’s picture

Patch #1 works pretty well for me, thanks! I hope this will be implemented in the next release.