FriendlyID韩国slu ..
当我用韩文添加文章时,例如: 신품
FriendlyID gem创建空白slug,url就像/8
…所以这是ID。 请看这个链接: http://www.srecipe.kr.com/articles/8
: http://www.srecipe.kr.com/articles/8
其他语言有效。
如何从신품
获取映射到拉丁字母的url,例如/ this-is-url?
与所有这些永久链接解决方案一样,友好ID使用parameterize
方法将字符串转换为URL安全字符串。 像这样:
require 'active_support/all' puts "Oh Hai There".parameterize => oh-hai-there
当您使用非ASCII字符串,参数化替换为空字符串,导致您的问题时,会出现此问题:
# encoding: UTF-8 require 'active_support/all' puts "신품".parameterize =>
ActiveSupport提供了一种通过transliterate
方法将非ASCII字符串更改为近似近似值的方法。
# encoding: UTF-8 require 'active_support/all' include ActiveSupport::Inflector puts transliterate("Ærøskøbing") => AEroskobing
但是,如果它不知道一个字符,它将默认为??
# encoding: UTF-8 require 'active_support/all' include ActiveSupport::Inflector puts transliterate "신품" => ??
但是,你可以告诉音译如何处理字符。 所以在Rails模型中
# Store the transliterations in locales/en.yml en: i18n: transliterate: rule: 신: "abc" 품: "def" puts transliterate "신품" => "abcdef"
因此,您可以使用transliterate(title).parameterize
而不仅仅是参数化。 如果你把韩语字母变成音译部分,你就会接近金色。
还没试过这些但是我要去:
- https://github.com/makimoto/romaji
- https://github.com/aelaa/hangul
- https://github.com/janx/ruby-pinyin
我会在尝试时报告回来。