Open johnhooks opened 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.
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
@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?
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:
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
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.
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
[ ] generate a POT file.
Currently running the cli command results in an error.
CLI error output
```sh PHP Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in phar:///Users/johnhooks/.bin/wp/php/WP_CLI/DocParser.php:75 Stack trace: #0 phar:///Users/johnhooks/.bin/wp/php/WP_CLI/DocParser.php(75): implode(Array, '\n') #1 phar:///Users/johnhooks/.bin/wp/php/WP_CLI/Dispatcher/CompositeCommand.php(32): WP_CLI\DocParser->get_longdesc() #2 phar:///Users/johnhooks/.bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(113): WP_CLI\Dispatcher\CompositeCommand->__construct(Object(WP_CLI\Dispatcher\RootCommand), 'cli', Object (WP_CLI\DocParser)) #3 phar:///Users/johnhooks/.bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(45): WP_CLI\Dispatcher\CommandFactory::create_composite_command(Object(WP_CLI\Dispatcher\RootCommand), 'cli', 'CLI_Command') #4 phar:///Users/johnhooks/.bin/wp/php/class-wp-cli.php(481): WP_CLI\Dispatcher\CommandFactory::create('cli', 'CLI_Command', Object(WP_CLI\Dispatcher\RootCommand)) #5 phar:///Users/johnhooks/.bin/wp/php/commands/cli.php(3): WP_CLI::add_command('cli', 'CLI_Command') #6 phar:///Users/johnhooks/.bin/wp/php/WP_CLI/Bootstrap/RegisterFrameworkCommands.php(32): include_once ('phar:///Users/j...') #7 phar:///Users/johnhooks/.bin/wp/php/bootstrap.php(75): WP_CLI\Bootstrap\RegisterFrameworkCommands->process (Object(WP_CLI\Bootstrap\BootstrapState)) #8 phar:///Users/johnhooks/.bin/wp/php/wp-cli.php(23): WP_CLI\bootstrap() #9 phar:///Users/johnhooks/.bin/wp/php/boot-phar.php(8): include('phar:///Users/j...') #10 /Users/johnhooks/.bin/wp(4): include('phar:///Users/j...') #11 {main} thrown in phar:///Users/johnhooks/.bin/wp/php/WP_CLI/DocParser.php on line 75 Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in phar:///Users/johnhooks/.bin/wp/php/WP_CLI/DocParser.php:75 Stack trace: #0 phar:///Users/johnhooks/.bin/wp/php/WP_CLI/DocParser.php(75): implode(Array, '\n') #1 phar:///Users/johnhooks/.bin/wp/php/WP_CLI/Dispatcher/CompositeCommand.php(32): WP_CLI\DocParser->get_longdesc() #2 phar:///Users/johnhooks/.bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(113): WP_CLI\Dispatcher\CompositeCommand->__construct(Object(WP_CLI\Dispatcher\RootCommand), 'cli', Object (WP_CLI\DocParser)) #3 phar:///Users/johnhooks/.bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(45): WP_CLI\Dispatcher\CommandFactory::create_composite_command(Object(WP_CLI\Dispatcher\RootCommand), 'cli', 'CLI_Command') #4 phar:///Users/johnhooks/.bin/wp/php/class-wp-cli.php(481): WP_CLI\Dispatcher\CommandFactory::create('cli', 'CLI_Command', Object(WP_CLI\Dispatcher\RootCommand)) #5 phar:///Users/johnhooks/.bin/wp/php/commands/cli.php(3): WP_CLI::add_command('cli', 'CLI_Command') #6 phar:///Users/johnhooks/.bin/wp/php/WP_CLI/Bootstrap/RegisterFrameworkCommands.php(32): include_once ('phar:///Users/j...') #7 phar:///Users/johnhooks/.bin/wp/php/bootstrap.php(75): WP_CLI\Bootstrap\RegisterFrameworkCommands->process (Object(WP_CLI\Bootstrap\BootstrapState)) #8 phar:///Users/johnhooks/.bin/wp/php/wp-cli.php(23): WP_CLI\bootstrap() #9 phar:///Users/johnhooks/.bin/wp/php/boot-phar.php(8): include('phar:///Users/j...') #10 /Users/johnhooks/.bin/wp(4): include('phar:///Users/j...') #11 {main} thrown in phar:///Users/johnhooks/.bin/wp/php/WP_CLI/DocParser.php on line 75 ```[ ] add translations for an initial set of messages.