Let facebook choose the right language with my share link - php

I have a multi-languages website (en_US + fr_FR), I made it using CakePHP.
The first time a user comes to my website, the language will be define using the $_SERVER['HTTP_ACCEPT_LANGUAGE'], or the default language (en_US) if $_SERVER['HTTP_ACCEPT_LANGUAGE'] is not set.
So the problem is that my OpenGraph tags are differents depending on the language, but the Facebook scraper doesn't have any $_SERVER['HTTP_ACCEPT_LANGUAGE'] var... so he'll always choose the default language (en_US), even if the user that clicked on the Share Link was French.
So my question is :
How can I force Facebook to choose a different language when scraping my webpage.
I already took a look at this url : https://developers.facebook.com/docs/opengraph/guides/internationalization/ but I didn't understand anything...
Please, help !
(actually I'll have to do the same thing with Google+ share link too... but Facebook is more important right now)
EDIT :
My webpage URL doesn't change when the language changes. It's always http://my-website.com/
EDIT 2 :
I think I managed to make it works.
The answer was really in the doc : https://developers.facebook.com/docs/opengraph/guides/internationalization/ but it was really hard to understand.
But now how can I change my language in Facebook to check that it really works (because now, it always gives me the French translation instead of the default language) ?

Actually, I had to add a way to set the website language using the URL :
http://my-website.com/en/ or http://my-website.com/?lang=en
It is much more easier this way to share my website in different languages AND this is a recommandation from Google

Related

How to Identify current locale in a site

I am using OJS cms, which is a Open Journals System.
I want to add some parts to registration page.
In registration page I want to know what language/locale is set, in order to put some more fields if specific language/locale is set.
I want current locale of the site. How can I recognize what locale is set by user by if statement? I searched stackoverflow but and found some result but non of them were helpful for me.
By the way, this cms is written by PHP. For more inforemation click here.
The best way is to use {$currentLocale}. It tells us what language the website is set in.

Getting page language and redirecting to same language page via polylang

I'm using polylang to translate my wordpress website and it's working fine until now...
The default language is english. Let's say I'm in a page in french, with a link to another page. I'd like it to be linked to that other page in french.
<a href="http://localhost:8888/lacolmena/a-propos/" class="apropos">
You'd say just add /fr at the end of the link. The thing is, I want it to detect which language is currently on and redirect the link to the equivalent language for the page I'm looking to get to.
Using Polylang, I managed to get all of my pages translated and working smoothly. I have a functional menu that allows me go to anywhere I want to go in any language. Only one link, in one page is causing me problems because it doesn't know if it could go the /fr or /en.
So I need to find a way to get if the current link if /fr or /en and redirect to the page in the equivalent language.
Basically :
my page is in french
go to the french contact page
or
my page is in english
go to the english contact page
I have no idea how to get to that. Should I be using PHP ? I've never used PHP before, so that's kind of creeping me out, even though I'm willing to make an effort to learn it.
I've seen this Polylang function while researching, perhaps it could be a beginning for my algorithm ?
pll_current_language($value);
I'm not sure my description is clear.. I'm really lost here :/
setup
<?php get_the_permalink(pll_get_post(get_page_by_path( 'page-slug' )->ID));?>
url path
URL TEXT
Try
get_the_permalink(pll_get_post(get_page_by_path( 'page-slug' )->ID));
It could look something like this
Contact

WordPress deployment for multiple websites and countries

I have a website e.g www.mysite.com and it content is in english. Now I need a feature which allows users to choose their residing country and directly take them to URL something like www.mysite.com/en/US. My questions:
How do I do the redirection from one url to another ?
Can I customize that the www.mysite.com/en/US will have more or less pages ?
How do I implement language selection for this scenario ?
Do I need more than one WordPress installation for this ?
Any tips or references is most welcome.
Download http://wordpress.org/plugins/qtranslate/, it's free and very easy.
It detect language from browser and you just need to set default language
see also http://www.wpmayor.com/best-wordpress-multilanguage-plugins/ for more info.

Automatically posting language specific posts on Facebook fan page

I know that on a Facebook fan page, if you want to make a post visible to only a specific set of people based on their facebook language we can do that. For Eg. If I want to post a post that is visible to only people who have set Facebook language to French, then I can set the "Make visible: language -> French" when I post it.
Now, I want to do this programmatically. I have 2 sets of text. I want to post one of them to a certain set of languages and other for just french. Say, first set for "English, Spanish, Polish" while the second set for just "French". How can I do this programmatically? Does facebook API allows us to do that?
Thanks.
I've not tried this but the documentation here https://developers.facebook.com/docs/reference/api/page/#posts seems to imply you can include a "targeting" property. Try playing around with that in the graph api explorer to see if it achieves what you are after. I'm assuming you know how to use the api as you merely mentioned the language side of it. If you don't know what you can do with the api then I suggest you check out the docs as mentioned by Matt in the comments

How to handle current language? Always in URL, or session?

Im planning to add language feature to my site. I can see two ways:
storing language in the url, so always www.mysite.com/en/introduce, www.mysite.com/en/home, or if 1st parameter is missing, just use the default. Its good for bookmark, but very hard to implement to all available links
storing in session. Way much easier, but users may gets confused not seeing the language in the URL.
I would say: session. What would you say? Any experiences?
If you want all your pages to be indexed by search engines, you'll have put the language parameter in the URL.
If you're producing more something like Facebook where a user needs to be logged in to receive content in his personalized language, use sessions.
I would use the first method togetter with a url rewrite engine.
F.e. when using RewriteEngine for Apache you could add this line to your .htaccess:
RewriteRule ^([a-zA-Z][a-zA-Z])/([a-zA-Z]*)$ content.php?culture=$1&content=$2
and even this can work:
RewriteRule ^([a-zA-Z][a-zA-Z])/([a-zA-Z]*)$ $2.php?culture=$1
You want to put your language as part of the url, otherwise google won't be able to index it for different countries. Also, they might think you have two types of content on the same page.
I would store it in session if there's only some parts of content changing as it's easier to implement if you're just changing i.e. contact details for the company based on what country the user is coming from. But as a general rule, give it a separate url either using .htaccess or your routing system.
Regular users don't look at URL and change the parameters from there. Normal users are point and click. Keep the language selection somewhere visible on the page and also in the user settings. This is not something that a user will want to change several times during a visit. We are talking about a setting that you can ask and set on the first visit. Currently I hate the way the google does it using my IP, assuming (wrong) that if I am entering from Norway I definitely speak Norwegian and I can handle finding in Norwegian menus the English version. I do like the way Etsy.com is doing it, they ask you on the first visit what is your preferred language, currency and so on. If you accept them good, but you can change them right there without having to navigate to a menu. In my opinion go for cookies or session instead of polluting the URL.

Categories