开发者

Special characters (and MooTools) are ruining my life

开发者 https://www.devze.com 2023-02-23 04:55 出处:网络
I\'m working on localization for my toolkit. My goal is that if you were a German web developer and you wanted to use a forEach loop, rather then type [\'hey\', \'there\'].forEach(function () {}); th

I'm working on localization for my toolkit.

My goal is that if you were a German web developer and you wanted to use a forEach loop, rather then type ['hey', 'there'].forEach(function () {}); they could type ['hey', 'there'].fürJeder(function () {});

I have all the words stored in an object at $.i18n.de.

In my JavaScript file I have

de: {
    extend: 'verlänger',
    forEach: 'fürJeder'
}

but when I go into the object to get the words they turn into verlänger and fürJeder.

I have no idea why.

Some details:

  • I'm on a MacBook Pro running 10.6.7
  • I'm using Kod as my editor.
  • I'm using Google Chrome as my browser.
  • I'm using Option + U + letter to type the ä and ü.

My question: How do I get the browser to handle these correctly?

I've tried using backslashes before them but it stays the same.

EDIT: Screw it. I just found out that the people who inspired me to do this did it as an April Fool's day joke. I really should've clicked on some of those links. It would've saved me 2 hours of trying to set up an API开发者_如何学编程.


Turns out that this is a really bad idea to try and do.

Programming languages are almost exclusively written in English (JavaScript being one of those) which means that even if you write your program in a different language, keywords like return, var, function are still going to be in English and you're still going to have to use them which would get confusing when using functions, constants etc. that have non-English names.

The best solution is to just avoid using non-latin characters in variable names all together.

Even thought it works in most modern browsers, it makes your code harder to write and more confusing.

Leave the coding to the English speakers.


Although I don't get the point of that (especially for german people generally comfortable with english and sharing the same germanic linguistic origin), the simplest workaround to avoid encoding issues is to replace those special characters with their latin counterparts:

fürJeder -> fuerJeder

verlänger -> verlaenger

Uncommon spelling but still correct

0

精彩评论

暂无评论...
验证码 换一张
取 消