简体   繁体   English

linkedin语言代码更改

[英]linkedin language code change

I am a beginner in programming and I have been able to add the linkedin share button to a test webpage. 我是编程的初学者,已经能够将linkedin共享按钮添加到测试网页。

I now want to change the language of the linkedin share button, so that it will change language when the user changes their language on the test web page. 现在,我想更改linkedin共享按钮的语言,以便当用户在测试网页上更改其语言时它将更改语言。

Linkedin users a five character langauge code (ru_RU, en_US, ko_KR, etc) . Linkedin用户使用五个字符的语言代码(ru_RU, en_US, ko_KR, etc) My test webpage uses a two character language code (ru, en, ko) , so I have to write a js function to return the five character language code. 我的测试网页使用两种字符的语言代码(ru, en, ko) ,因此我必须编写一个js函数以返回五种字符的语言代码。

I am using django 1.4 and the "{{ user.get_profile.language_preference }}" returns the two character language code. 我正在使用django 1.4, "{{ user.get_profile.language_preference }}"返回两个字符的语言代码。

Here is what I attempted to "convert" the language code: 这是我试图“转换”语言代码的内容:

        <script type="text/javascript">
        function language_code_extended(){
            var language_code_value = "{{ user.get_profile.language_preference }}";
            if ( language_code_value == ru ) { 
                return "ru_RU"
            }
            else if ( language_code_value == "fr" ) { 
                return "fr_FR"
            }
            else if ( language_code_value == "ko" ) {  
                return "ko_KR"
            }
            else {
                return "en_US"
            }
        }
    </script>

Here is my linkedin share button code: 这是我的linkedin共享按钮代码:

    <!-- LinkedIn Like Button code -->
    <script src="//platform.linkedin.com/in.js" type="text/javascript">
        //lang: ru_RU
        lang: language_code_extended()
    </script>

This does not work. 这是行不通的。 Can someone point out what I have done wrong? 有人可以指出我做错了什么吗?

Thanks. 谢谢。

Probably you need to quote the strings you're comparing to, for example: 可能需要引用要比较的字符串,例如:

language_code_value == ru

should be 应该

language_code_value == "ru"

otherwise the comparison will be looking for a variable named ru to compare to. 否则,比较将寻找一个名为ru的变量进行比较。

There are a few additional issues to address in making this conversion: 进行此转换时,还需要解决一些其他问题:

  • Having an if condition test for every language you'll want to deal with is quickly going to become unwieldy and error prone. 对要处理的每种语言进行if条件测试将很快变得笨拙且容易出错。

  • This mapping is taking a language code ru and mapping to a code representing and language and a country ru_RU . 此映射采用语言代码ru并映射到表示和语言以及国家/地区ru_RU的代码。 This involves making an assumption that somebody speaking a certain language is in a certain country, which is not generally correct. 这涉及假设有人说某种语言是在某个国家/地区,这通常是不正确的。 Many languages are spoken in multiple countries with different conventions in each. 在多个国家/地区使用多种语言,每个国家/地区使用不同的约定。

It might be worth your while to dig a little deeper to find a better way of doing this. 可能值得您花一些时间深入研究以找到一种更好的方法。 This will likely result in less effort and a more correct solution. 这可能会减少工作量并提供更正确的解决方案。

I'm sorry, I don't know Django so I can't point you in the right direction, but you might want to explore whether it, or a third party package, can return you the correct IETF language tag directly. 抱歉,我不了解Django,所以我无法指出正确的方向,但是您可能想研究一下它还是第三方软件包是否可以直接为您返回正确的IETF语言标记。

Edit 编辑

You're also going to have problems with: 您还将遇到以下问题:

var language_code_value = "{{ user.get_profile.language_preference }}";

language_code_value is going to have the literal string value {{ user.get_profile.language_preference }} which is never going to compare equal to the two digit language codes you want to compare it to. language_code_value将具有文字字符串值{{ user.get_profile.language_preference }} ,该字符串值永远不会比较等于要与之比较的两位数字语言代码。

通过使用其他方法(不是JavaScript)解决了此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM