You are here

Drupal专业开发指南 第18章 在settings.php中覆写字符串

g089h515r806 的头像
Submitted by g089h515r806 on 星期二, 2009-08-25 16:03

老葛的Drupal培训班 Think in Drupal

找到你的settings.php文件(一般位于sites/default/settings.php)。在进行修改以前,你可能首先需要修改这个文件的权限,将其改为可写的,因为Drupal总是尽可能的将其保持为只读的。滚读到settings.php的结尾处。我们将添加下面的自定义字符串数组:
 
/**
 * String overrides:
 *
 * To override specific strings on your site with or without enabling locale
 * module, add an entry to this list. This functionality allows you to change
 * a small number of your site's default English language interface strings.
 *
 * Remove the leading hash signs to enable.
 */
# $conf['locale_custom_strings_en'] = array(
#  forum' => 'Discussion board',
#  @count min' => '@count minutes',
# );
 
$conf['locale_custom_strings_en'] = array(
    Home' => 'Sweet Home',
);
 
    如果你访问你的站点,你将会注意到,在面包屑中,“Home”(首页)已被修改为了“Sweet Home”(美丽家园),如图18-2所示。
    现在你应该知道如何覆写字符串了,让我们继续前进,把单词“Blog”替换为“Journal”:
 
$conf['locale_custom_strings_en'] = array(
    Blog' => 'Journal',
);
 
    接着,导航到“管理➤站点构建➤模块”,启用博客模块。然后访问“创建内容➤博客条目”,你将看到如图18-3所示的一幕。
 
18-2.面包屑中的字符串“Home”被替换为了“Sweet Home”。
 
18-3.字符串“Blog entry”未被替换为“Journal entry”。
 
    哪里出错了?为什么你自定义的字符串替换数组不起作用呢?这是因为字符串“Blog entry”与字符串“Blog”不完全相同。你不能只挑选子字符串进行替换;你必须匹配整个字符串。
    如何才能找到包含单词“Blog”的所有字符串?这样你就可以使用它的“Journal”等价字符串逐一进行替换了。本地模块可以帮你实现这一点。
 
提示 由于不需要调用数据库,所以在settings.php文件中覆写字符串是很高效的(仅用于小量的字符串集);而字符串的替换只需简单的查找一个数组就可以了。对于字符串的覆写,你不需要为其启用本地模块。另外还有一个第3方的字符串覆写模块,地址为http://drupal.org/project/stringoverrides
 

Drupal版本:

评论

biglazy 的头像

# $conf['locale_custom_strings_en'] = array(
'forum' => 'Discussion board',
#  @count min' => '@count minutes',
# );
 
$conf['locale_custom_strings_en'] = array(
    'Home' => 'Sweet Home',
);
$conf['locale_custom_strings_en'] = array(
    'Blog' => 'Journal',
);