-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC Replace or upgrade Zend_Translate #6221
Comments
Very rough proof of concept at https://github.com/open-sausages/silverstripe-framework/commits/pulls/4.0/i18n-symfony |
Added fixes for cms at https://github.com/open-sausages/silverstripe-cms/tree/pulls/4.0/i18n-symfony framework tests are more or less passing finally, after discovering a big hole in my initial proof of concept. :) |
A couple of notes after a discussion with @tractorcow:
|
Implemented PR at #6558 |
A bit more discussion with Damian: Text collection is only one workflow to manage translations in your SilverStripe code. More advanced teams might skip this step in favour of managing translations separately. I've worked on enterprisey projects where each UI message was collected in a wiki by BAs before the development started, and it's easy to see how that would apply to translations as well (managed in dedicated external tools). This approach might not be in line with our Agile values, but that doesn't mean we should prohibit it from a SilverStripe API perspective. With this in mind, it doesn't make sense to require a default The I don't see "context" as an advanced use case, it's a practice that should become more rather than less frequent in core. Translators are looking at strings in transifex completely out of context, so rely on these annotations e.g. to identify if something is a noun or verb, a short button label or a message window with lots of room for longer translations. That being said, the On a related note, I'm recommending to keep JavaScript translations in the YAML master files instead of JSON (see "Notes" in RFC description here). This works around the issue that JSON can't store comments, hence we can't pass on context through to transifex there. |
I've updated based on feedback and requested changes. I've deviated slightly from my expected plan slightly, which I'll describe below.
I've made this a warning, but it's possible to turn this warning off.
It was troublesome to resolve duplicate strings where there are many non-empty versions of a string across modules, so I've opted to continue not collecting empty strings. Based on discussion with @chillu, we feel that the i18n system is presented as the standard localisation system we expect to be used within silverstripe, but the i18nTextCollector is specific to the format we use for our own core and release process (based on yml / transifex). With that in mind, if someone had a custom localisation format (and wrote their own localisation reader / writer) then they could also write their own text collector. It being a warning is probably sufficient for our needs.
After discussion with @chillu I've restored this, but solidified the API slightly. The "normalised localisation" data for any key can now have a "comment" key, as well as a "default" key. This normalised data is available to be read from / written to the Reader / Writer interfaces. However, our standard YmlReader / YmlWriter is currently discarding this key intentionally. However, it opens the door for custom localisation formats, such as those listed on https://docs.transifex.com/formats/introduction, which may support this metadata.
Instead of doing this, I've simply rolled pluralisation into the _t method. I've used string-inspection to detect if we are attempting to localise (contains '{count}' and a single '|' character). This means we get text-collection for plurals for free (which I'd otherwise have to do another day). |
Updated at #6558 |
I often see strings like "This {item} saved sucessfully", where "This" can be translated - depeding on the item - as "Dieser", "Diese" or "Dieses" (male, female, thing) in German. Are there concepts available to address this issue? |
We could use pluralisation, which allows us to present record-specific grammar.
However the obvious downside is the generic usage of numbers, rather than the "this" or "the" grammar which might be more appropriate in certain contexts. How do you feel about this? |
this/the is according to the saved /deleted etc. DataObject, so i guess the DataObject should know if it's male/female/thing? E.g. CMSMain.NEWPAGE: "Neue {pagetype}" could be "Neue FooSeite" but "Neuer Kalender", depending on the (german) name of my page type. |
@wernerkrauss Yeah the |
Split out from RFC Replace Zend_Locale with new i18n backend
Introduction
SilverStripe uses Zend Framework v1 for message translations (
i18n::_t()
) throughZend_Translate
. This dependency is out of date, Zend has declared EOL in September 2016. Our goal is to either upgrade or replace the library.We've written a custom YAML adapter, since
Zend_Translate
doesn't support the format natively. TheZend_Translate
API is used both indirectly ini18n::_t()
, and directly throughi18n:: register_translator(<Zend_Translate>)
.Solution Requirements
Note: Some of these requirements might be fulfilled by the existing
i18n
class.i18n:: include_by_locale()
)de_AT
=>de
)i18n::$default_locale
i18n::_t()
is called dozens of times on each CMS render_t()
call_t('There are %s monkeys', [5])
)LeftAndMain.SAVE
)Options
1. Symfony Translate
Currently at version 3.1. Seems to have native support for string placeholders. Initial impression is that the symfony localisation is slightly more polished and feature-rich than zend. Documentation http://symfony.com/doc/current/translation.html
Dependencies: (400k)
2. CakePHP
Currently at version 3.3. This library is similar to zend framework in that it provides a wrapper around php-intl extension. However, internally message translation is handled via the aua.intl extension (https://github.com/auraphp/Aura.Intl). If necessary we could extract the message translation directly from aura.intl, and rely directly on php-intl for string and number formatting. Documentation http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html
Dependencies: (600k)
3. Zf2-i18n
Currently at version 2.7, which is also the current version for this component in the current zend-framework 3.0. The good news is that this implies the 2.x branch of this module will be supported within the immediate future. This is probably the least disruptive upgrade as zendframework/zend-i18n replaces Zend_Translate API.
The API has seen a major rewrite between 1.x and 2.x (before vs. after), so it's unclear how much rewrite effort is required on our side (e.g. for the custom Rails YAML adapter). It's likely limited since we don't use a lot of its API surface.
Documentation at https://docs.zendframework.com/tutorials/i18n/ and https://framework.zend.com/manual/2.4/en/modules/zend.i18n.translating.html
Dependencies: (1.5mb)
4. Write our own i18n wrapper around php-intl
Take the
i18n
class as a base and replicate the message loading and locale fallback management via a new SS API. Use php-intl for the actual message formatting (placeholders, plurals). This would essentially replicate the API surface existing for Zend/Symfony/CakePHP libraries. It also means we're likely just writing our own YAML loader, leaving devs who rely on other formats in SS3 throughZend_Translate
stranded in SS4.Notes
php-intl
MessageFormatter API is pretty minimal (single-message only), so we need a library solution on top of it either wayRelated
The text was updated successfully, but these errors were encountered: