Django templates: Get current URL in another language

I’m not using language prefixes, but translated urls instead. However, this template tag should also help you: # This Python file uses the following encoding: utf-8 from django import template from django.core.urlresolvers import reverse # from django.urls for Django >= 2.0 from django.core.urlresolvers import resolve # from django.urls for Django >= 2.0 from django.utils import … Read more

Chrome timeZone option to Date.toLocaleString()

update There is pretty extensive write-up about the API here Is this part of a new standard? Perhaps buried somewhere in ECMAScript 6? Or is it just something custom to Chrome? Yes, these are part of the ECMAScript Internationalization API. It is implemented separate from ECMAScript, but the requirement of implementing ECMAScript Internationalization API is … Read more

HTML tags in i18next translation files in React

Don’t put the HTML tags in the translation. It’s a bad idea anyway. Separation of concerns guys will be all whiny about it. Use the <Trans> component if react-i18next https://react.i18next.com/latest/trans-component Do like so: // Component.js <Trans>Welcome, <strong>User!</strong>, here’s your <strong>broom</strong></Trans> And the corresponding translation file: // your locales/starwars_en.js file translations: { “Welcome, <1>User!</1>, here’s your … Read more

Same string with different translation

You can use gettext’s context for that. Django has added support for that in 1.3 release (in code) and 1.4 (for templates), see https://docs.djangoproject.com/en/dev/topics/i18n/translation/#contextual-markers Update: For example following code: from django.utils.translation import pgettext, ugettext month = pgettext(“month name”, “May”) month = pgettext(“fifth month”, “May”) month = ugettext(“May”) Translates to: #: foo/views.py:4 msgctxt “month name” msgid … Read more

Django templates: Best practice for translating text block with HTML in it

From the docs: It’s not possible to mix a template variable inside a string within {% trans %}. If your translations require strings with variables (placeholders), use {% blocktrans %} instead. Then under blocktrans: To translate a template expression — say, accessing object attributes or using template filters — you need to bind the expression … Read more

Ruby on Rails 3, incompatible character encodings: UTF-8 and ASCII-8BIT with i18n

Ok so problem solved after some hours of googling… There was actually two bugs in my code. The first one was a file encoding error and the second was the problem with the MySQL Data base configuration. First, to solve the error caused by MySQL I used this two articles : http://www.dotkam.com/2008/09/14/configure-rails-and-mysql-to-support-utf-8/ http://www.rorra.com.ar/2010/07/30/rails-3-mysql-and-utf-8/ Second, to … Read more