Is it somehow possible to translate text in title?

E.g. I have title for specific content:

[current-page:page-title] - keyword [node:field-mesto:name], second keyword | [site:name]

and I need keyword and second keyword to be translated in different languages.

Is there any possibility?

Thank you in advance for any idea!

Files: 
CommentFileSizeAuthor
#6 i18npagetitle.zip1.12 KBjasom

Comments

Tony Sharpe’s picture

I also need D7 version multi-language support for page title patterns, as in D6 thread http://drupal.org/node/383358. Any thoughts on this?

adelka’s picture

Meanwhile, I found solution.

  1. I have installed custom tokens module http://drupal.org/project/token_custom.
  2. I have created new tokens - www.yoursite.com/admin/structure/token-custom - I've used php snippet to translate words
  3. I've used custom token in page title configuration page

I used this php snippet for each word I needed to be multilingual:

<?php  
 
global $language;
 
$lang_name = $language->language;
  if (
$lang_name == "en" ) print "page";
  if (
$lang_name == "sk" ) print "str.";
 
?>

Of couse, its not very flexible (if you have many languages or you plan to add more later) but its solution for now.

Goekmen’s picture

Thanks... your solution helped me out!

matulis’s picture

Here is my use case for mulitlingual site with 2 languages - EN / FR.
I needed multilingual pattern for content type : News (Actualité), machine name = news.

1. Install module : Variable
2. in custom module implement hook

<?php
function CUSTOMMODULENAME_variable_info($options) {
 
$variables['page_title_type_news'] = array(
   
'type' => 'text',
   
'title' => t('News page title', array(), $options),
   
'default' => '',
   
'description' => t('Module : Page title', array(), $options),
  );
  return
$variables;
}
?>

Inspect pattern input name in admin/config/search/page-title to find out variable name,
for content types it will be 'page_title_type_CONTENTTYPENAME',
for user profile 'page_title_user'.

3. make variable mulitlingual on admin/config/regional/i18n/variable

4. now you can see language switcher on admin/config/search/page-title and define different patterns for each language :

pattern for English version = [current-page:page-title] | News | [site:name]
pattern for French version = [current-page:page-title] | Actualités | [site:name]

jasom’s picture

#4 works perfect for me, tnx matulis.

page_title_vocab_VOCABMACHINENAME for vocabulary page title
page_title_default for default page title
page_title_front for front page title

jasom’s picture

StatusFileSize
new1.12 KB

Here is upload of module based on #4. It's 7.1 edit of module used in my site (have more custom hooks at original one).

In this is 7.1 edit is set multilingual page title for content type page and article, taxonomy tags, default and front page. You will need probably to edit it and add hooks for your content types names and taxonomy names.

Let me know if it works.

i.explose’s picture

@matulis Thanks, this is working perfectly!

@jasom thanks for the file, it's working great!

SiliconMind’s picture

Issue summary:View changes

Couldn't we just run the pattern through t() before passing it to token_replace?
This seems to be the least intrusive way of making this module more multilingual friendly. I know it's not very pretty but would be great for a start.

It would also it make sense to invoke token_replace with correct language option. Passing language object to token_replace makes sense because some functions might use LANGUAGE_NONE instead of current site language if language is not provided.

<?php
function page_title_page_get_title($raw = FALSE) {
 
$title = &drupal_static(__FUNCTION__);

  if (
is_null($title)) {
   
   
/*
     * Removed part of the code to make changes clear.
     */

    // Translate pattern
   
$page_title_pattern = t($page_title_pattern);

    global
$language;

   
// Apply token patterns using token_replace
   
$title = token_replace($page_title_pattern, $types, array('sanitize' => FALSE, 'language' => $language));
  }

 
// Trim trailing whitespace from the title
 
$title = trim($title);

  return
$raw ? $title : filter_xss($title);
}
?>
jabberwooki’s picture

#4 works perfect for me too, thanks a lot matulis.

In addition, it's possible to implement hook_variable_group_info()
(see details in variable.api.php which is included in the Variable module)
and so you get your page title settings in their own vertical tab in admin/config/regional/i18n/variable.

For instance, below is what I did :

<?php
/**
 * Implements hook_variable_group_info().
 */
function YOUR_MODULE_variable_group_info() {
 
$groups['page_title_pattern_settings'] = array(
   
'title' => t('Page title patterns'),
   
'description' => t('Page title patterns'),
   
'access' => 'administer site configuration',
  );
  return
$groups;
}
?>
Pravin Ajaaz’s picture

@jabberwooki : can you pls explain me how to use that variable tab to translate page title...