Translate Easy Notification Bar with WPML?
-
Hi,
Because the notification settings are customizer settings you should be able to translate them via the WPML String Translations add-on using the “Translate texts in admin screens” link.
I made a quick video to show you: https://a.cl.ly/12uA6W1m
– AJ
Heads up – I tried the video tutorial and it completely breaks the plugin in the original language.
Message keeps returning:
[theme_mods_SDF-Child-Theme][easy_nb]messageButton keeps returning:
[theme_mods_SDF-Child-Theme][easy_nb]button_textButton link keeps returning:
[theme_mods_SDF-Child-Theme][easy_nb]button_linkReinstalling the plugin doesn’t help.
Out of curiosity, why didn’t you add a simple
<?php echo __( 'Your String', 'your-context'); ?>
for the message, text and button links and make the plugin instantly compatible with WPML?
Hi,
The reason I am not using the __() function for the customizer settings is because localization functions shouldn’t be used to translate dynamic data such as variables or user input, these functions should only be used to localize “fixed” strings.
When you translated them via the string translations settings did everything work correctly in the secondary language but not the primary? If so, I’m thinking maybe this could be an issue with the setup as perhaps WPML is using the string translation for all languages as opposed to using the default customizer values for the primary one.
The Customizer is a core WordPress function and there are hooks available to modify the return value of theme mods – https://developer.www.ads-software.com/reference/hooks/theme_mod_name/ – so translation plugins should be able to hook into these to modify the return value and provide native support.
When looking at their docs, this is the only thing they mention in the docs – https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/#strings-arent-selected-for-translation – which is basically just to search and register the theme mods, essentially as I mentioned above.
Now, since you are using a child theme it would be possible for you to manually register the strings with WMPM instead of using their admin panel. I wrote some sample code for you based on their docs here: https://wpml.org/documentation/support/translation-for-texts-by-other-plugins-and-themes/
if ( function_exists( 'icl_register_string' ) ) { $easy_nb_settings = array( 'message' => esc_html( 'This is your default message which you can use to announce a sale or discount.', 'easy-notification-bar' ), 'button_text' => esc_html( 'Get started', 'easy-notification-bar' ), 'button_link' => 'https://www.ads-software.com/plugins/easy-notification-bar/', ); $easy_nb_mods = get_theme_mod( 'easy_nb' ); foreach( $easy_nb_settings as $key => $default ) { $mod = $easy_nb_mods[$key] ?? $default; //note: this code requires PHP 7.0+ do_action( 'wpml_register_single_string','Easy Notification Bar', 'easy_nb__' . $key, $mod ); } }
One more thing to mention, looking at their pricing page it seems that only their more expensive solutions offer support for “Translate texts in theme and plugins admin” – so perhaps if you are on the basic solution you aren’t able to actually properly translate customizer settings?
I can try my best to assist but can only help so much without having access to the latest version of the premium WPML plugin or a deeper understanding on it’s internal functions. And since the plugin is only using native WordPress functions it should be supported by all 3rd party plugins.
If you do contact WPML and get a response from them, I would love to know what the fix was incase any other customer runs into similar issues. Thanks!
– AJ
Hey AJ,
Thank you for your insanely long reply. ??
Unfortunately, due to time constraints we had to switch to Notibar which actually registers the inputs from Customizer in String Translation immediately.
To answer your questions: Yes, this is correct – the secondary language worked at first, but the primary didn’t. So, thinking it was a random bug, we replaced the primary language with secondary. This further broke the plugin and then we were stuck with the same buggy notices in both languages.
We are using a WPML lifetime license and are not locked out behind any features.
I’ve tried your code and it’s still bugged. If it matters, we are using Avada Theme (Child) + WPML. Both are at their latest versions as of today.
On a side note – why does the Notice bar activate immediately after being activated as a plugin? We used it on a live site, so imagine the panic when a placeholder that doesn’t do anything went live on a site with about 100+ realtime users…
Regards,
DorianHi Dorian,
Thank you for your reply!
It is strange that the code doesn’t work and that the strings aren’t just translating natively. I’ll see if I can recreate the issues locally with WPML and if I can and can’t fix them I will reach out to WPML to see if we can test things out together and get things working as expected.
I did download the Notibar plugin out of curiosity and it looks like they are actually storing separate options in the database just for WPML with essentially the same values as the theme mods – https://a.cl.ly/OAunGKmd. So it’s creating extra bloat, I’m not a big fan of that, there shouldn’t be any need to store duplicate values in the database.
I actually provide full support for WPML in my Total theme and use the Customizer as well and essentially used the same methods mentioned above to provide support for Customizer translations. The only difference is my theme is using their older “icl_register_string” function instead of the newer “wpml_register_single_string” action hook, so I wonder if perhaps there is a bug with the hook or maybe you need to clear some sort of cache when adding the code to your site. For example, I know when you modify the wpml-config.xml file in a theme or plugin any new strings need to be fetched by the plugin to work correctly. I’ll investigate further.
Anyway, I’ll figure things out and make sure it’s done well and efficiently ??
The reason I have the notice bar display by default is to prevent confusion so you can tell right away when enabling the plugin that it works or not.
Since every WordPress site should be using a caching solution the bar shouldn’t be displayed to visitors until you’ve cleared your cache anyway so it shouldn’t be a concern. But I do understand what you mean and I’ll keep an eye out to see how others feel about that. I do update my products based on customer feedback and what I feel will be best for everyone.
I really appreciate your feedback and reply. Thanks!
Anyway, feel free to ignore my long reply, I just wanted to make sure to respond for you or anyone else interested in my response.
– AJ
Ok, I tested on a fresh installation and it’s working perfectly for me: https://a.cl.ly/6quYvOe1 (without any added code or plugin tweaks)
So maybe a theme/plugin conflict or issue with a specific WPML setting.
- This reply was modified 3 years, 2 months ago by wpexplorer.
- The topic ‘Translate Easy Notification Bar with WPML?’ is closed to new replies.