我需要用另一种语言显示我的注册页面,将其与自然行为分开。 特别是此页面必须在其拥有的网站页面上以英文显示,但我需要在意大利语中将其显示在另一个网站上的iframe中。 现在,常识告诉我我需要一个页面
www.example.com/user
和
www.example.com/it/user
我尝试通过“admin / config / regional / language / configure”和“从URL确定语言(路径前缀或域)”选项来实现此目的。并且一切正常,但是,由于某些原因,当我激活此选项时,我的所有网站页面都会在其网址中显示“/ en /”,从而将很多内容分解到网站中(这非常复杂)。 有一种方法只能为注册页面实现此行为吗? (能够调用www.example.com/it/user页面以显示意大利语注册并且www.example.com/user和网站中的所有其他页面无需任何更改即可运行吗?)
答案 0 :(得分:1)
我的解决方案是一个小型自定义模块。
优点:
缺点:
.info文件:
name = User Registration Languages
description = Alter the user registration form to present alternative translations
core = 7.x
.module file
<?php
/**
* implements hook_form_FORM_ID_alter()
* https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_FORM_ID_alter/7
*
* @param $form
* @param $state
*/
function userreglang_form_user_register_form_alter(&$form, &$state) {
// the arg() function returns a path component (zero based index)
// https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/arg/7
// in this case we're looking for:
// user/register/{language_arg} e.g user/register/it
$lang = arg(2);
// uncomment the following if you want take a look at the form array prior to modification
// be sure to temporarily give the anonymous user role the ability to "Access developer information"
/*if(module_exists('devel')) {
dpm($form);
} // */
if($lang && $map = _userreglang_languages($lang)) {
$form['account']['name']['#title'] = $map['name'];
$form['account']['name']['#description'] = $map['name_desc'];
$form['account']['mail']['#title'] = $map['mail'];
$form['account']['mail']['#description'] = $map['mail_desc'];
$form['actions']['submit']['#value'] = $map['button'];
}
// uncomment the following if you want take a look at the form array after modification
/*if(module_exists('devel')) {
dpm($form);
} // */
}
/**
* helper function for different language maps you might have for the user registration form
*
* @param $lang
* @return array|null
*/
function _userreglang_languages($lang) {
$map = [
'it' => [
'name' => 'Your name, yo!',
'name_desc' => 'Input your username fool!',
'mail' => 'Email, you gots it?',
'mail_desc' => 'Seriously do you not know what email is?',
'button' => 'Click it baby!',
]
];
if(isset($map[$lang])) {
return $map[$lang];
}
else {
return null;
}
}
答案 1 :(得分:0)
在drupal.stackoverflow上我得到了一个更简单的答案。这是:
导航到您网站中的/ admin / config / regional / language,并验证这些内容(并在适当的地方更正):
使用“英语”作为默认语言 使用该页面上“英语”的“编辑”链接,它将带您进入“/ admin / config / regional / language / edit / en”。在该页面上,确保“路径前缀语言代码”的值为“空白”。