4

ユーザーの言語を正しく検出する (サイトの言語はそれに応じて変更される) 多言語ウェブサイトを持っていますが、Google+ で正しく共有できません。

このサイトは 2 つの言語で存在するため、言語ごとに 1 つずつ、2 つの異なるメタ プロパティのセットを設定しました。

英語:

<link rel="canonical" href="http://en.perehana.com/"/>

<meta property="og:title" content="Perehana, the best way to find perfect gifts!"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="http://www.perehana.com"/>
<meta property="og:image" content="http://www.perehana.com/img/large-icon.jpg"/>
<meta property="og:site_name" content="Perehana"/>
<meta property="og:description" content="No gift ideas for Christmas, birthdays, weddings, births or any other event? Perehana allows you to enter gift ideas and to reserve your family and friends' ideas before buying them."/>
<meta property="og:locale" content="en_GB"/>
<meta property="fb:app_id" content="242045389185230"/>
<meta property="og:locale:alternate" content="fr_FR"/>

<meta itemprop="name" content="Perehana, the best way to find perfect gifts!"/>
<meta itemprop="description" content="No gift ideas for Christmas, birthdays, weddings, births or any other event? Perehana allows you to enter gift ideas and to reserve your family and friends' ideas before buying them."/>
<meta itemprop="image" content="http://www.perehana.com/img/square_logo.png"/>

フランス語:

<link rel="canonical" href="http://fr.perehana.com/"/>

<meta property="og:title" content="Perehana, le meilleur moyen de faire plaisir à coup sûr !"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="http://www.perehana.com"/>
<meta property="og:image" content="http://www.perehana.com/img/large-icon.jpg"/>
<meta property="og:site_name" content="Perehana"/>
<meta property="og:description" content="En manque d'idées de cadeaux à l'approche de Noël, des anniversaires, des mariages ou des naissances ? Perehana est un site qui vous permet de saisir des idées-cadeaux et de réserver celles de votre famille et de vos amis. Vous pouvez ensuite aller les acheter sans qu'ils le sachent."/>
<meta property="og:locale" content="fr_FR"/>
<meta property="fb:app_id" content="242045389185230"/>
<meta property="og:locale:alternate" content="en_GB"/>

<meta itemprop="name" content="Perehana, le meilleur moyen de faire plaisir à coup sûr !"/>
<meta itemprop="description" content="En manque d'idées de cadeaux à l'approche de Noël, des anniversaires, des mariages ou des naissances ? Perehana vous permet de saisir des idées-cadeaux et de réserver celles de votre famille et de vos amis. Vous pouvez ensuite aller les acheter sans qu'ils le sachent."/>
<meta itemprop="image" content="http://www.perehana.com/img/square_logo.png"/>

ご覧のとおり、ロケールと代替が正しく設定されています。

これは、私が G+ API を呼び出す方法です (これはフランスのユーザーの例です)。

<div class="g-plusone" data-size="medium" data-href="http://www.perehana.com"></div>

<script type="text/javascript">
    window.___gcfg = {
        lang: 'fr'
    };

    (function() {
        var po = document.createElement('script'); po.type = 'text/javascript';
        po.async = true;
        po.src = 'https://apis.google.com/js/plusone.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
    })();
</script>

ユーザーの言語に従って、正しいプロパティが表示されます。

この問題は、Google+ で共有したいときに発生します。Google が自動的に選択するサイトのタイトルと説明は英語ですが、G+ ユーザー アカウントがフランス語である場合でも... :-(

助けてくれる人に感謝します!

4

1 に答える 1

1

ウェブサイトでこれを行うために Accept-Language HTTP ヘッダーを使用していると思います。

Google+ での共有に使用されるページ フェッチャーは、アクションを開始したユーザーから HTTP ヘッダーを伝達しないため、Web サイトはデフォルトの言語にフォールバックします。

この問題は、GET パラメータを使用して言語を設定することで回避できます。+1 ボタン、共有ボタン、または共有リンクから共有している場合は、現在の言語をそのプラグインのターゲット URL パラメータに設定できます。data-href

Google+ イシュー トラッカーで、この機能のリクエストを既に提出されているようです。心当たりがない場合は、課題にスターを付けて、更新通知を受け取ります。

于 2012-07-23T18:35:59.097 に答える