WordPress / wp-feature-notifications

WP Feature Notifications - a proposal to modernise the way in which WordPress handles emails, admin notices and user notifications
https://wordpress.github.io/wp-feature-notifications/
GNU General Public License v2.0
189 stars 19 forks source link

Add support for internationalization. #209

Open johnhooks opened 1 year ago

johnhooks commented 1 year ago

What problem does this address?

There currently isn't any support for translating the notification messages.

What is your proposed solution?

Add a basic translation file to the project.

Requirements

johnhooks commented 1 year ago

@erikyo I don't have any experience with WordPress localization, do you know the basics so we can get started? Because as soon as we get the db test data filled we will want this in place so we can actually render notifications.

erikyo commented 1 year ago

This is one of the many nice things WordPress does for you, and you don't need anything else to apart adding the "languages" folder in your plugin and do this https://codex.wordpress.org/I18n_for_WordPress_Developers#Loading_a_Text_Domain

johnhooks commented 1 year ago

@erikyo because of how we decided to do the notificaton messages with title_key and message_key, and channels have name_key and description_key, we need to manually add entries in order for them to be looked up by the translating functions. Does that make sense?

johnhooks commented 1 year ago

Summary of thoughts from Discussion #113.

I believe the translation of a notification has to happen when it is emitted and stored in the database for the following reasons:

erikyo commented 1 year ago

yes i agree 100%. Currently it seems the most viable and functional option.

If notifications are stored per user it is assumed that user knows the language he uses, so i don't see anything so disadvantageous in this proposal

johnhooks commented 1 year ago

Perhaps this system shouldn’t be trying to tackle translations. It should provide a way for plugins to emit notifications. Leave providing translations to the plugins or new developments into how internationalization works. They are very different problems.

It will be difficult to save actionable and possibly customizable messages in a format which can be dynamically rendered in another language, especially when depending on third party code that would be required to indefinitely remain on the system to render the notification.

We could provide an API to query the languages preferences the users subscribed to a channel, and handle linking the correct translated message to the appropriate users when a notification is emitted.