From 838e2b953420fb6fe5d2b2f97f56de14cfd9564d Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Tue, 7 Sep 2021 17:10:37 +0200 Subject: [PATCH] Support Cyrillic and Latin character sets for Serbian. See https://github.com/collective/plone.app.locales/issues/326. This is a forward port of https://github.com/plone/plone.i18n/pull/37 from 4.x to master. --- news/326.feature | 3 +++ plone/i18n/locales/languages.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 news/326.feature diff --git a/news/326.feature b/news/326.feature new file mode 100644 index 0000000..784a46f --- /dev/null +++ b/news/326.feature @@ -0,0 +1,3 @@ +Support Cyrillic and Latin character sets for Serbian. +See `locales issue 326 `_. +[maurits, fredvd] diff --git a/plone/i18n/locales/languages.py b/plone/i18n/locales/languages.py index ea0b7ec..817f5e1 100644 --- a/plone/i18n/locales/languages.py +++ b/plone/i18n/locales/languages.py @@ -3,6 +3,8 @@ from plone.i18n.locales.interfaces import IMetadataLanguageAvailability from zope.interface import implementer +import os + @implementer(ILanguageAvailability) class LanguageAvailability: @@ -460,6 +462,10 @@ class MetadataLanguageAvailability(LanguageAvailability): "flag": "/++resource++country-flags/al.gif", }, "sr": { + # Note: we support two character sets for this language. + # See zope_i18n_allowed_languages below. + # TODO: in Plone 6.0 native should become 'Srpski', + # but that requires copying sr@Latn to sr in plone.app.locales. "native": "српски", "name": "Serbian", "flag": "/++resource++country-flags/cs.gif", @@ -553,6 +559,23 @@ class MetadataLanguageAvailability(LanguageAvailability): }, } +# Character sets are a thing now. +# See https://github.com/collective/plone.app.locales/issues/326 +# At the moment only for Serbian. +_zope_i18n_allowed_languages = os.environ.get("zope_i18n_allowed_languages", "") +if "sr@Latn" in _zope_i18n_allowed_languages: + _languagelist["sr"] = { + "native": "Srpski", + "name": "Serbian (Latin)", + "flag": "/++resource++country-flags/cs.gif", + } +elif "sr@Cyrl" in _zope_i18n_allowed_languages: + _languagelist["sr"] = { + "native": "српски", + "name": "Serbian (Cyrillic)", + "flag": "/++resource++country-flags/cs.gif", + } + # convert the utf-8 encoded values to unicode for code in _languagelist: value = _languagelist[code]