Title: Hook into language detection function?
Last modified: August 30, 2016

---

# Hook into language detection function?

 *  Resolved [Boyan Raichev](https://wordpress.org/support/users/studioreforma/)
 * (@studioreforma)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/hook-into-language-detection-function/)
 * What I would like to achieve is set the site language based on the country (detected
   by IP) , upon a user’s first visit. I see there is a filter qtranslate_detect_language
   in function qtranxf_detect_language and it seems like this is the filter I need
   to use, but I can’t find anything about it on the plugin site, so decided I would
   ask here before I start experimenting with it 🙂 Plus, it might help others that
   need something similar.
 * What I presume, is that I should use:
    `add_filter('qtranslate_detect_language','
   my_detection_function',10,1);`
 * and then in the function:
    – first I check if $url_info[‘doing_front_end’] is
   true, as I don’t need this for the admin – the I set $url_info[‘language’] to
   the language I want, using the 2-letter code – I echo $url_info back
 * Would that be enough?
 * [https://wordpress.org/plugins/qtranslate-x/](https://wordpress.org/plugins/qtranslate-x/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [Boyan Raichev](https://wordpress.org/support/users/studioreforma/)
 * (@studioreforma)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/hook-into-language-detection-function/#post-6439206)
 * OK, so the filter above DID work for me, although it took me some time to set
   it up properly 🙂
 * I’ve made the whole thing into a very light plugin that checks with an IP database
   and then sets your site language based on the country (with rules you set up 
   in the admin). Plus, there is a hook AND a GLOBAL for further actions by other
   themese/plugins (for example, set up shop currency as well). The plugin will 
   be on wordpress.org soon.
 *  [BossManPL](https://wordpress.org/support/users/bossmanpl/)
 * (@bossmanpl)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/hook-into-language-detection-function/#post-6439207)
 * Wow i was searching it, can you tell me wheen plugin will be on wordpress ?
 *  Thread Starter [Boyan Raichev](https://wordpress.org/support/users/studioreforma/)
 * (@studioreforma)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/hook-into-language-detection-function/#post-6439208)
 * Yesterday 🙂
    [https://wordpress.org/plugins/ip-loc8/](https://wordpress.org/plugins/ip-loc8/)
 * I forgot to include a small detail in instructions, I will update it soon, but
   in the meantime here it is:
    Country codes should be UPPERCASE and language codes
   should be lower case.
 * In the next version I will change it so it does not matter if you write upper
   or lower case, but until then you need to obey those rules 🙂
 *  Thread Starter [Boyan Raichev](https://wordpress.org/support/users/studioreforma/)
 * (@studioreforma)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/hook-into-language-detection-function/#post-6439209)
 * and of course you need a key from api.ipinfodb.com, but this is obvious on the
   settings page
 *  [BossManPL](https://wordpress.org/support/users/bossmanpl/)
 * (@bossmanpl)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/hook-into-language-detection-function/#post-6439210)
 * thanks mate, you are the best !
 *  Plugin Author [John Clause](https://wordpress.org/support/users/johnclause/)
 * (@johnclause)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/hook-into-language-detection-function/#post-6439211)
 * Thank you very much for this plugin, I listed it on page: [https://qtranslatexteam.wordpress.com/compatible/](https://qtranslatexteam.wordpress.com/compatible/)
   
   😉
 * I like your logo, seems like you have designer skills. Would you have time to
   make some logo for qTranslate-X? Contact us privately then: [https://qtranslatexteam.wordpress.com/contact-us/](https://qtranslatexteam.wordpress.com/contact-us/)
 * Thanks a lot!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Hook into language detection function?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/qtranslate-x_f9f9f9.svg)
 * [qTranslate X](https://wordpress.org/plugins/qtranslate-x/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/qtranslate-x/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/qtranslate-x/)
 * [Active Topics](https://wordpress.org/support/plugin/qtranslate-x/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/qtranslate-x/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/qtranslate-x/reviews/)

## Tags

 * [country](https://wordpress.org/support/topic-tag/country/)
 * [detection](https://wordpress.org/support/topic-tag/detection/)

 * 6 replies
 * 3 participants
 * Last reply from: [John Clause](https://wordpress.org/support/users/johnclause/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/hook-into-language-detection-function/#post-6439211)
 * Status: resolved