问题
The following hash is causing a syntax error. I assume it is because of the funky characters.
Any way to fix this? I'm using macvim, in case that matters.
{
:en => ['English', 'en_US'],
:es => ['español', 'es_MX'],
:fr => ['français', 'fr_FR'],
:de => ['Deutsch', 'de_DE'],
:ru => ['русский', 'ru_RU'],
:zh => ['中国的', 'zh_CN'],
:ar => ['العربية', 'ar_AR'],
}
回答1:
If this is Ruby 1.9, then you can set the magic comment to tell Ruby this is a UTF8 file instead of ASCII:
How does the magic comment ( # Encoding: utf-8 ) in ruby work?
回答2:
You could always escape your unicode values.
{
:en => ['English', 'en_US'],
:es => ['espa\u00F1ol', 'es_MX'],
:fr => ['fran\u00E7ais', 'fr_FR'],
:de => ['Deutsch', 'de_DE'],
:ru => ['\u0440\u0443\u0441\u0441\u043A\u0438\u0439', 'ru_RU'],
:zh => ['\u4E2D\u56FD\u7684', 'zh_CN'],
:ar => ['\u0627\u0644\u0639\u0631\u0628\u064A\u0629', 'ar_AR'],
}
来源:https://stackoverflow.com/questions/14495486/ruby-syntax-error-with-multiple-language-in-hash