there is no need to separate code from translatable labels. your plug_get_labels
function suffers from the following issues
-
Translation tools can show you the context in which the label is being used which helps in making a good translation faster. With your function you lose context.
-
the use of such function encourage you to call it every time your code is being run and not only when a translation is needed. this might result in negative performance as loading the translation file and parsing it is relatively slow, and it makes you use extra memory (translation files are loaded only when a translation is required). of course if the number of translated strings is small there will not be a big impact.
Your json solution is truly bad. You lose the ability to use tools like poedit to do the translation because their use require that the first parameter to __
will be a literal string and not a variable.
Related Posts:
- How to make a WordPress plugin translation ready?
- How to provide translations for a WordPress TinyMCE plugin?
- Preparing a string in an array for localization
- Shortcodes, output buffering, and WordPress functions
- Problems with localization
- Multiple textdomains
- How to properly load text domain of custom mu plugin
- `wp_set_script_translations` with `wp.i18n` does not return translated strings in simple plugin
- WordPress Localization and Templating
- How to properly load text domain of custom mu plugin
- Can’t we use strings defined as PHP constants if we want to translate them in a plugin?
- How to update the language used by wordpress from a plugin
- WordPress: After Gutenberg plugin migration to block.json the localization/ translations with PolyGlot in JavaScript does not work anymore
- Singular name Plugin localization
- How to i18n text coming from the db or from an external source
- Should I always prefer esc_attr_e & esc_html_e instead of _e?
- Some strings from a .mo file do not load
- Should shorcodes in i18n plugins be translated and if so, how?
- How to render a time-of-day string like ’16:42′ with a site’s chosen time format?
- Frontend language per user
- Generate JSON files for language translation from po file without wp-cli i18n make-json
- Shortcode returning localized HTML part
- load_plugin_textdomain doestn’t work with add_action plugins_loaded
- How to prevent someone from entering strings without making it available for translation?
- I18n not working in plugin
- Mixing l18n string from my plugin with WordPress’ translations
- Plugin language always shows WP site language, not profile language
- Is hint for translator compulsory while internationalizing a string containing variables?
- Do I lose translations when I change my Text domain for my plugin on wp.org?
- Transform internationalized plugin into internationalized mu-plugin?
- Translation not working for Constant strings in Plugin
- How are themes and plugins localized using the gettext GNU framework?
- Save translation file of third party plugin in a custom plugin?
- React Plugin Settings Page Localization
- How to get locale within WP REST Request?
- How can a plugin create a page/form in the front end?
- How to add Request header in WordPress remote api calls
- Init action hook running late after PayPal’s return url?
- Get specific color from admin color scheme
- wp_remote_get doesn’t work with secure connections https?
- How do you create a custom edit.php / edit pages page
- Edit the output of wp_widget_rss_output()
- Why are two functions over-riding each other?
- Should I ask my Twitter plugin users to create their own Twitter App and API Keys to use my plugin?
- Dequeue theme stylesheets but keep widget styling on custom page template
- WP_Query with tax_query, order by most ‘matches’
- Using the Settings API, how should I add multiple values to an option?
- WP custom menus error > menu name already exists?
- Plugin updates, version dependencies, and backwards compatibility
- Where and how does WordPress store and use its plugin and hook information?
- Cache directory needed for plugin
- How to sanitize user input?
- Remove Internal Style Sheet if no Value Provided?
- When to use add_settings_section vs just register_setting?
- How to customize login process
- How should I store a log for my plugin
- Adding more text to a post, after it was published
- How to modify the comments to be displayed in a post?
- what is the difference between these phares?
- WP_Query filters
- Plugin Architecture Question: How to avoid using transients
- SSL certificate verify failed
- How to load library scripts in admin from plugins in noConflict wrapper?
- wordpress how to query wp_options table
- rest_no_route on custom API endpoint wordpress
- How to only load css for used blocks on frontend
- adding wp-cli commands to plugin: how to document to users?
- Creating an empty page programatically
- Multiple API Endpoints (wp_remote_get)
- plugin_dir_url & plugin_basename not working when plugin dir is outside wordpress dir
- How to replace default comments with custom HTML?
- Call to undefined function is_home() or any conditional tags
- Make dynamic string translatable
- wp_schedule_event is registered but function isn’t running
- Simple plugin don’t display content
- How to make an admin plugin menu page go full screen?
- Gutenberg – Call google map render function in save after DOM has been rendered
- Woocommerce get_term_by() in transition_post_status hook doesn’t works
- Home page is not loading, where in other pages are displaying on the site
- Custom table / Alternative to WP_List_Table
- Why is that only the first row getting inserted into Mysql table when i import csv file on backend custom plugin?
- Adding Amchart Interface to WordPress API
- WordPress with React: Saving and Using Data Collected with fetch
- bindParam? WordPress 4.9.5 SQL LIKE statement %s and %LIKE%
- tweaking the
- Plugin with functions inside a class & how to trigger WP CRON
- external Integration with wordpress timeout error
- add_settings_error on validating plugin options API
- Problem to return more than single line captions
- Unable to show a message after plugin activation
- Use plupload to upload images and save them to custom folder and database table
- How to add conent (text) to Add New pages form of admin in WordPress
- Can I access WordPress API’s from within plugin scripts?
- Ajax url value to pass ‘variable’ to use in query
- Apply Filters Causing a 500 Internal Server Error
- Open media box library from link
- Using tag or inline style attribute?
- remove () from category number [closed]
- How will i add an option under customizer the event calendar section?
- Is it possible to add Custom Dashboard Widgets to Custom Admin Menu Page?