-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
A "type" could be a plugin that defines a type "Website" or "MobileApp". For example while a type "Website" may use the wording "Website and Websites" another type "MobileApp" may want to use the wording "Mobile App and Mobile Apps".
This will be needed for #7131, #4734 and #7826
Ideally, we would not use words like "Website", "Site", "Websites", "Sites" in translations but instead placeholders like %s
(formatted strings via eg sprintf
) whenever we want to use any website related term.
By default we should use a generic wording eg "Property and Properties" (see #7826). A plugin defining the type "Website" would rename those generic words to "Website and Websites". This will help us to avoid to have different wordings like "Website and Site". Sometimes, it would maybe make sense to use a generic term in general and not use %s
at all. Eg instead of "No websites found" we could use "No matches found".
Does anyone have an idea how to achieve this? Such translations are composed pretty much everywhere and I doubt that we always have an $idSite
(the type depends on the idSite). We would kinda need something like a static "::getCurrentType()" that is aware in which context we are and returns the correct type. So basically something like Piwik::translate('MyKey', getCurrentType()->getName())
. If we handle multiple siteIds we need to use the generic wording. Meaning getCurrentType()
would not return a specific type like "Website" or "MobileApp" but the "Generic" type.
Maybe we could use in translations something like ::property::
and ::properties::
that will be replaced at some point with "Website/Property" and "Websites/Properties"? Would this help somehow? But again at some point we need to replace this term and then we need to know which type we are currently handling. Doing it only in the Metadata API will most likely not work. I think we used such placeholders like this already somewhere but don't remember where. Does anyone?
To be considered
- We do have to take care of lower/upper case. Eg we have "Website" and "website". In some languages it would be still "Website" and "Website". Eg in German many more words use a capital letter than in English. When using
%s
we would never know whether a lower or upper case version should be applied since it depends on the language. Here those placeholders could be interesting as a translator could eg use::property::
or::Property::
. - We have similar problem for metrics. Eg the metric
nb_visits
is used in the report nameVisits by days since last visit
. Ideally a type would not have to rename all report names that contain the word "Visits" or "Visit" but only the actual words / metric "Visit" and "Visits" once. - We do have this event
getClientSideTranslationKeys
which allows plugin classes to make translations available client side. If someone uses eg hard coded$translations[]= 'General_Website'
, then we have a problem again. I don't think it is a big problem but we have to take care of such uses.
Another possible solution would be to just rename a translated term. Eg when current language is German ("Website" (en) => "Webseite" (de)) we would translate all words like "Website" and "Websites" into German to find out which words need to be replaced. Eg str_replace(Piwik::translate('Website'), getCurrentType()->getName(), 'My translated string')
. One problem again would be whether to use ucfirst
/ lcfirst
. Using placeholders would be better I think. This is rather a hacky solution.
Referencing @sgiehl as it is related to translations.