Drupal 视图非拉丁字母词汇表

发布于 2024-11-26 16:22:15 字数 497 浏览 1 评论 0原文

好吧,我在 drupal.org 和 stack Overflow 上搜索过,但没有找到类似的问题,我希望我没有错过任何东西。

我正在 drupal 7 中构建一个网站,其中的内容需要按字母分组。术语表中构建的视图似乎是最好的解决方案,而且效果很好。唯一的问题是我使用了非拉丁字母,例如 Č Đ Č Š Ž,并且顺序混乱。我需要的顺序类似于 Gaj 的拉丁字母

ABC Č Ć D Dž Đ EFGHIJKL Lj MN Nj OPRS Š TUVZ Ž

正如你所看到的,还有一个问题,因为有“两个字母”的字母”,但将 Lj 显示为 L 将是我可以接受的解决方案。最大的问题是C和Ć显示在Č下,但Đ与D分开,所以我得到:

A (1) | Č (3) | D (1) | Ž (1) |以(1)为例。

对于这个问题有一个优雅的解决方案吗?将 C 和 Ć 与 Č 分开或合并 D 和 Đ。请帮忙。

Well, I have searched on drupal.org and stack overflow and couldn't find a similar problem, I hope i didn't miss something.

I'm building a site in drupal 7 where I have content that needs to be grouped by letters. The views build in glossary seems the best solution and it works well. The only problem is that I use non Latin letters like Č Đ Č Š Ž and the order is messed up. I need the order to be like in Gaj's Latin alphabet:

A B C Č Ć D Dž Đ E F G H I J K L Lj M N Nj O P R S Š T U V Z Ž

as you can see there is also a problem because there are letters with "two letters", but displaying Lj as L would be a solution I could live with. The biggest problem is that C and Ć is displayed under Č but Đ is separated from D, so i get:

A (1) | Č (3) | D (1) | Ž (1) | Đ (1) for example.

Is there an elegant solution for this problem? To seperate the C and Ć from Č or to merge D and Đ. Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小忆控 2024-12-03 16:22:15

我在这个聚会上已经很晚了,

坏消息:这完全是由于 SQL 排序规则而不是视图造成的。 Drupal 的常用数据库排序规则,utf8_general_ci 指示 MySQL 在 GROUP 和 WHERE 语句中将这些字符视为相等。

尤其;当前用于生成术语表的视图查询是:

SELECT SUBSTRING(node.title, 1, 1) AS title_truncated, COUNT(node.nid)
AS num_records
FROM 
{node} node
WHERE (( (node.status = '1') AND (node.type IN  ('my_nodetype')) ))
GROUP BY title_truncated
ORDER BY title_truncated ASC
LIMIT 10 OFFSET 0

这里的 GROUP BY 消除了排序规则列出为相等的 unicode 字符之间的任何差异,因为它将它们分组并视为相等。

好消息:通过实现 hook_views_query_alter() 来指示 MySQL 进行 GROUP 和 WHERE 对视图使用排序规则 utf8_bin ,可以很快解决这个问题。

/**
 * Implementation of hook_views_query_alter().
 */
function mymodule_views_query_alter(&$view, &$query) {
  if ($view->name == 'my_view') {
    // Stop the glossary from treating characters equal.
    if ($view->is_attachment) {
      foreach ($query->groupby as &$condition_group) {
        if ($condition_group == 'title_truncated') {
          $condition_group = "title_truncated COLLATE utf8_bin";
        }
      }
    }
    // Rewrite the attached view to filter on unique characters.
    else {
      foreach ($query->where as &$condition_where) {
        foreach ($condition_where['conditions'] as &$cur_condition) {
          if ($cur_condition['field'] == 'SUBSTRING(node.title, 1, 1) = :node_title') {
            $cur_condition['field'] = 'SUBSTRING(node.title, 1, 1) = :node_title COLLATE utf8_bin';
          }
        }
      }
    }
  }
}

希望这对遇到这种情况的其他人有所帮助。

I am quite late to the party on this one,

The bad news : This is entirely due to SQL collation and not Views. The usual database collation for Drupal, utf8_general_ci instructs MySQL to treat those characters as equal in GROUP and WHERE statements.

In particular; the views query to generate a glossary is currently:

SELECT SUBSTRING(node.title, 1, 1) AS title_truncated, COUNT(node.nid)
AS num_records
FROM 
{node} node
WHERE (( (node.status = '1') AND (node.type IN  ('my_nodetype')) ))
GROUP BY title_truncated
ORDER BY title_truncated ASC
LIMIT 10 OFFSET 0

The GROUP BY here obliterates any difference between collation-listed-as-equal unicode characters, because it groups and treats them as equal.

The good news : this is quickly solved by implementing hook_views_query_alter() to instruct MySQL to GROUP and WHERE to use the collation utf8_bin for your view.

/**
 * Implementation of hook_views_query_alter().
 */
function mymodule_views_query_alter(&$view, &$query) {
  if ($view->name == 'my_view') {
    // Stop the glossary from treating characters equal.
    if ($view->is_attachment) {
      foreach ($query->groupby as &$condition_group) {
        if ($condition_group == 'title_truncated') {
          $condition_group = "title_truncated COLLATE utf8_bin";
        }
      }
    }
    // Rewrite the attached view to filter on unique characters.
    else {
      foreach ($query->where as &$condition_where) {
        foreach ($condition_where['conditions'] as &$cur_condition) {
          if ($cur_condition['field'] == 'SUBSTRING(node.title, 1, 1) = :node_title') {
            $cur_condition['field'] = 'SUBSTRING(node.title, 1, 1) = :node_title COLLATE utf8_bin';
          }
        }
      }
    }
  }
}

Hopefully this is helpful to anyone else encountering this situation.

我不是你的备胎 2024-12-03 16:22:15

你们的网站都是俄语的吗?如果是这样,请检查此页面,开箱即用您的语言安装 Drupal 7.0!在 localize.Drupal.org 上找到了 drupal.org 的本地化子域,该子域致力于以英语以外的语言创建 Drupal 站点。使用 Drupal 7,可以安装多种语言的本地化版本,包括俄语。

虽然我还没有尝试过,但我相信安装本地化版本以查看术语表是否按您希望的方式工作是值得的。如果没有,请回到这里告诉我们。

Is your site all in Russian? If so, please check this page, Install Drupal 7.0 in your language out of the box! It is found at localize.Drupal.org the localization subdomain of drupal.org, which is dedicated to creating Drupal sites in languages other than English. With Drupal 7, it is possible to install a localized version in many languages, including Russian.

While I haven't tried it, I believe it would be worthwhile to install a localized version to see if the glossary works as you would like. If not, let us know back here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文