JavaScript validation issue with international characters

I think the email and url validation methods are a good reference here, eg. the email method: email: function(value, element) { return this.optional(element) || /^((([a-z]|\d|[!#\$%&’\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&’\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value); }, The script to compile that regex. In other words, replacing your arbitrary list of “crazy moon” characters with this could help: [\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF] Basically this avoids the character encoding issues … Read more

Changing the default date and time format in Rails 4

Found a nice approach through the Rails Internationalization (I18n) API Data and time formats can be ‘translated’ by adding the format to the i18n configuration. config/locales/en.yml en: date: formats: default: “%d/%m/%Y” time: formats: default: “%d/%m/%Y %H:%M” Note: remember to not have tabs for the indent, like I did first time 🙂 As mentioned by NoelProf … Read more

In what JS engines, specifically, are toLowerCase & toUpperCase locale-sensitive?

Note: Please, note that I couldn’t test it! As per ECMAScript specification: String.prototype.toLowerCase ( ) […] For the purposes of this operation, the 16-bit code units of the Strings are treated as code points in the Unicode Basic Multilingual Plane. Surrogate code points are directly transferred from S to L without any mapping. The result … Read more

Turkish case conversion in JavaScript

Coming back to this years later to provide more up to date solution. There is no need for the hack below, just use String.toLocaleUpperCase() and String.toLocaleLowerCase() “dinç”.toLocaleUpperCase(‘tr-TR’) // “DÄ°NÇ” All modern browsers support this now. [ OLD, DO NOT USE THIS ] Try these functions String.prototype.turkishToUpper = function(){ var string = this; var letters = … Read more

Fall back to default language if translation missing

Nowdays there’s no need for using separate i18n gem, on plain Rails 3.0.6 and above (5.0 included) installation, fallbacks value can be one of the following: # application.rb # rails will fallback to config.i18n.default_locale translation config.i18n.fallbacks = true # rails will fallback to en, no matter what is set as config.i18n.default_locale config.i18n.fallbacks = [:en] # … Read more

Passing variables inside rails internationalization yml file

The short answer is, I believe, no you cannot do string interpolation in YAML the way you want using an alias. In your case, what I would do is have something like the following in my locale file: en: site_name: “Site Name” static_pages: company: description: ! ‘%{site_name} is an online system’ and then call in … Read more