PHP can read the ‘HTTP_ACCEPT_LANGUAGE’ header from the browser request, but this might not be easy to parse if there is more than one accepted language set. For the simplest case, when one language is set as accepted, you need to read only first 2 characters from this header:
$language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
But, most WordPress language strings are more complex than that (there are few variations of English, and some languages have many variations too), so you would need to convert 2 letter language code into WordPress language code.
Also, HTTP_ACCEPT_LANGUAGE might not be included at all in the request, it depends on the browser.
Related Posts:
- How to get a translated string from a language other than the current one?
- How to get a localized version of WordPress from a repository?
- Working with l10n contexts (_x etc)
- How to escape the single quote character in i18n translation strings?
- How to escape single and plural i18n text strings?
- What are the most used WordPress localization?
- Difference between 2 internationalization (i18n) functions __() & _e()
- Localization works but still get “This plugin is not properly prepared for localization” msg in directory
- How to load theme textdomain from plugin?
- Can’t we use strings defined as PHP constants if we want to translate them in a plugin?
- get_the_date() for translating date format
- Should i use _n for pronouns in translation?
- POEdit with Custom mu-plugins code
- How does WordPress choose which translation file to use?
- Proper way to create / manage gettext (.po, .pot) files?
- Should I include colon in my msgid in PO file?
- _e() function get text_string from function
- Translations not returning translated strings
- Force translated language on front
- Translating dynamic strings
- WordPress translation loading english file
- Easy export/import of data for Translation
- How can I see my theme’s text domain?
- WordPress Theme .mo-file won’t load
- How to become a translator on wordpress.org?
- Translation from .mo file not working in theme
- How to prevent someone from entering strings without making it available for translation?
- Localization, escape html elements mid-sentence
- How to translate “$before” with get text in get_the_term_list?
- WordPress localization – gettext and git
- How to ignore extra whitespaces in translation functions like _e?
- /languages/ folder missing in default themes
- How to translate functions.php?
- Localization of WP theme
- WordPress Translations
- Post types translation
- Translate arguments of a user added custom code [closed]
- Internationalize plugin so strings can be translated in WPML [closed]
- localization of theme and plugins to English (originally in another language)
- Interface translation without plugins
- Translation not working for Constant strings in Plugin
- Plugin localization persistance (woocommerce)
- WordPress Localization error within return value
- Custom theme .mo translation file not working
- Plugin translation not displaying
- WordPress translation
- Tweak the loop for translation
- Translating form labels shortcode output
- Does WPML translate numbers automatically, or do I have to do the string translation? [closed]
- Website Language/Locale Switching
- .po file is loaded but changes are not appearing
- Theme localization of “slugs” (custom post types, taxonomies)
- gettext does not translate when called in ajax
- Changing the language of a single page
- what’s different between _x() and _()
- Obtain a list of available translations
- How to add extra language packs to WordPress
- load_plugin_textdomain in `plugins_loaded` or `init`?
- Translate Navigation Menu & Sidebar Widget Titles
- How to handle single quote in a translatable string in WordPress
- WordPress: After Gutenberg plugin migration to block.json the localization/ translations with PolyGlot in JavaScript does not work anymore
- How can I make “Leave a comment” translation ready?
- Multiple text-domains per single plugin – admin and frontend
- Where the WordPress Core Translation is “actually” taking place?
- How to translate theme name
- How to save a translation of a plugin in “CodeStyling Localization”?
- Using polylang, how can I see which post is the “original” and which are the “translated children”? [closed]
- Making my plugin translation ready. Poedit not working
- Where is the right .mo file inside the language repository?
- setlocale for date
- where to set the PO file for a plugin?
- Should shorcodes in i18n plugins be translated and if so, how?
- Internationalization and functions that use it
- How to syntax Json output for translation?
- Translating a word with locotranslate, but wordpress does display another by default
- Two text domains in one plugin
- How do I translate month names in post metadata?
- Translate theme only
- what’s different between _x() and _()
- Making a string translation ready with html in it
- Translation for plugin
- Translate custom order status through a filter?
- Translation with wordpress what does the process involve?
- Is hint for translator compulsory while internationalizing a string containing variables?
- How to translate custom Divi module using POEDIT and Polylang [closed]
- How to add a translatable string to post date
- Proper way to use esc_html__ and esc_attr__ etc for escaping value for translation
- How to use esc_attr__ with custom translation function?
- Translate a theme with a PO file
- How to define theme translation file?
- WordPress Translation to french, at -> à not working
- Translations not working on Safari
- printf, translation function and date_i18n adds extra characters
- How to deal with differently translated prepositions?
- Language & translation
- How to translate placeholder?
- Display Today’s date outside the loop?
- Poedit ASCII errors ( WordPress )
- Translations in source code
- Theme translation file translating some strings and not translating others