简体   繁体   English

如何在AngularJS脚本中使用孟加拉语?

[英]How can I use Bengali in an AngularJS script?

I have an app that is using Angular. 我有一个使用Angular的应用程序。 I am loading a JSON file to display data on the page in different languages. 我正在加载JSON文件,以便以不同的语言在页面上显示数据。 This works fine with all other languages so far, but I get an error when the variable values are in Bengali. 到目前为止,这在所有其他语言中都可以正常使用,但是当变量值位于孟加拉语时,我会报错。 The error is "SyntaxError: Unexpected token in JSON at position 38". 错误是“ SyntaxError:JSON在位置38处出现意外令牌”。

I have already ensured that the server response is in UTF-8. 我已经确保服务器响应为UTF-8。 If I use naked JavaScript (aka no libraries or frameworks), the JSON object can be parsed with no problem. 如果我使用裸JavaScript(也就是没有库或框架),则可以毫无问题地解析JSON对象。

app.js app.js

var App = angular.module('myApp', []);

App.controller('myCtrl', function($scope, $http) {
    $scope.setLang = function(language) {
        document.getElementById("rootElement").lang = language;

        $http.get('_customizable/languages/' + language + '.js', {header: {"Content-Type":"application/json; charset:utf-8"}})
           .then(function(res){
              $scope.translated = res.data;                
            }
        );
    }
    $scope.setLang(document.getElementById("rootElement").lang);
});

bn.js bn.js

{
   "Applications":"অ্যাপ্লিকেশন",
   "AccountSettings": "অ্যাকাউন্ট সেটিংস",
   "AuthorizationManager": "অনুমোদন ম্যানেজার ",
   "DCCMaintenance": "ডিসিসি রক্ষণাবেক্ষণ",
   "MastercardClearing": "মাস্টারকার্ড ক্লিয়ারিং",
   "ParticipantManager": "অংশগ্রহণকারীর ম্যানেজার",
   "PropertiesManager": "বৈশিষ্ট্যাবলী ম্যানেজার",
   "VisaClearing": "ভিসা ক্লিয়ারিং",
   "WorkflowManager": "কর্মপ্রবাহ ম্যানেজার",
   "Users": "ব্যবহারকারী",
   "Groups": "দল",
   "RecordsSearch": "রেকর্ডস অনুসন্ধান",
   "UserName": "ব্যবহারকারীর নাম",
   "Search": "খোঁজো",
   "Reset": "রিসেট",
   "UserRecords": "ব্যবহারকারীর রেকর্ডস",
   "Delete": "মুছে ফেলুন",
   "AllRightsReserved": "সমস্ত অধিকার সংরক্ষিত."
}

Note: This even returns an error on several online JSON editors, such as http://www.jsoneditoronline.org/ 注意:这甚至会在多个在线JSON编辑器上返回错误,例如http://www.jsoneditoronline.org/

So......it took getting a hold of the original file instead of the one pasted in here (benefit of working together) but the problem has been found. 如此……花了一个原始文件的保全,而不是粘贴在这里的文件(一起工作的好处),但是发现了问题。

The first clue something was odd is that copying the version posted here into a json validation site worked. 第一个奇怪的线索是,将此处发布的版本复制到json验证站点中是可行的。

So, when I compared the original file to the one posted here in a hex editor we were able to spot the difference. 因此,当我将原始文件与在十六进制编辑器中发布的文件进行比较时,我们能够发现差异。 When the original English version of the file was dropped into Google Translate to convert to Bengali the 3 leading spaces in front of each line were changed from 0x20 0x20 0x20 to 0xC2 0xA0 0xC2 0xA0 0x20. 当文件的原始英文版放入Google Translate转换为孟加拉语时,每行前面的3个前导空格已从0x20 0x20 0x20更改为0xC2 0xA0 0xC2 0xA0 0x20。

So....the moral of the story, don't translate EVERYTHING in your file, just translate the smaller pieces that need translating. 所以……故事的寓意,不要翻译文件中的所有内容,而只翻译需要翻译的较小部分。

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

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