-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement i18n/l10n solution for shared library files #7
Comments
The proposed solution will work fine for any plugin that's not delivered from WordPress.org. I wrote to UK WP Community Hi, I'm trying to implement a shared library solution for some of my plugins on WordPress.org where the same PHP file is delivered by each plugin that needs it and that file may contain strings that need translating. Basically I want WordPress to ignore the text-domain parameter and find any available translation. I think I need to look into solutions that will do just what I said in the last sentence. |
Having found I could happily use null as a text domain I wrote to core slack
Sergey Biryukov asked what's "Just Translate It"? My reply was.
Actually I wrote some tests to prove this was possible. Now I'm wondering what's the best approach for implementing the solution. My gut feel is to continue using null as the parameter. |
Using a null domain is a different approach. With this method there is no need to build language files for the oik-libs libraries. We just use what's delivered by the plugins. So, instead of changing oik_require_lib() to automatically load the oik-libs text domain, we leave it to the plugins and libs. A library that requires translation will need to perform the following.
Then the next call to This solution does not cater for strings requiring context. e.g. "Check" - when used for banking. |
I have raised WordPress TRAC 41551 to Officially support use of null for text domain name parameter to l10n functions. See https://core.trac.wordpress.org/ticket/41551 The new unit tests only demonstrate that you can pass a value of null to:
I've also written tests for oik-libs ( in tests/test-translate-null-domain.php ) that demonstrated the proposed solution. I then developed the solution in libs\oik-l10n.php with tests in tests\test-libs-oik-l10n.php. Explanation of proposed solutionmakepot finds the strings
translators translate the strings
users want the strings translated
Use of null text domain
"Just Translate It" logicImplemented as a side effect in the
|
There are some strings in the shared libraries where applying a translation from another text domain may produce the wrong result. An example is the word Check. In oik-libs source code this word is being used as the verb. In some plugins the word may be used as a noun, being the US spelling of cheque. If a plugin/theme uses this word in that way then, in UK English, we could end up getting an unwanted Cheque. To avoid this situation we should use the _x() function, passing a value for $context which clearly indicates it's not a bank cheque. We need to test that the correct value is returned when another domain contains the unwanted translation. |
Having reconciled the shared libraries in oik with those in oik-libs most of the Deprecated logic has been catered for except code in |
The shared library files are incorporated into multiple plugins. Some of them include translatable strings. We need to develop the most appropriate solution for ensuring that these strings are translated into the user's preferred language.
In the solution being developed for bobbingwide/oik/issues/9, rather than using the slightly more efficient solution originally developed in oik, we are changing the code to use the standard functions that support localization (l10n). The shared library files will need to be changed to use this same set of APIs. The replacement functions, that do not perform translation, are in class-BW-.php.
We then have to decide how to build and deliver .po and .mo files for each supported locale.
Proposal
oik-libs
languages/oik-libs-la_CY.mo
The text was updated successfully, but these errors were encountered: