admin管理员组

文章数量:1332873

THE SITUATION:

I am using angular-translate for my app.

Everything was working perfectly. But i just needed to move the translations into static json files.

I have followed all the instructions but is not working.

THE CODE (BEFORE):

$translateProvider.translations('en', {

    "WELCOME": "Wele",
});

$translateProvider.translations("tr", {

    "WELCOME": "Hoşgeldiniz",
});

$translateProvider.translations("it", {

    "WELCOME": "Benvenuto",
});

THE CODE (NOW):

$translateProvider.useStaticFilesLoader({
    prefix: '/translations/',
    suffix: '.json'
});

JSON FILES:

path:

www/translations/en.json

www/translations/it.json

www/translations/tr.json

Example:

{
    "WELCOME": "Benvenuto",
}

ERROR:

SyntaxError: Unexpected token } in JSON at position 4160
at Object.parse (native)

THE QUESTION:

How can i load the translations from static json using angular-translate?

What can be wrong in my case?

Thank you!

THE SITUATION:

I am using angular-translate for my app.

Everything was working perfectly. But i just needed to move the translations into static json files.

I have followed all the instructions but is not working.

THE CODE (BEFORE):

$translateProvider.translations('en', {

    "WELCOME": "Wele",
});

$translateProvider.translations("tr", {

    "WELCOME": "Hoşgeldiniz",
});

$translateProvider.translations("it", {

    "WELCOME": "Benvenuto",
});

THE CODE (NOW):

$translateProvider.useStaticFilesLoader({
    prefix: '/translations/',
    suffix: '.json'
});

JSON FILES:

path:

www/translations/en.json

www/translations/it.json

www/translations/tr.json

Example:

{
    "WELCOME": "Benvenuto",
}

ERROR:

SyntaxError: Unexpected token } in JSON at position 4160
at Object.parse (native)

THE QUESTION:

How can i load the translations from static json using angular-translate?

What can be wrong in my case?

Thank you!

Share Improve this question edited Jun 10, 2016 at 14:07 FrancescoMussi asked Jun 10, 2016 at 13:54 FrancescoMussiFrancescoMussi 21.6k40 gold badges129 silver badges181 bronze badges 3
  • Do you know which file triggers the error? If not try them one by one and look what is at position 4160. Should be a } too much – KRONWALLED Commented Jun 10, 2016 at 14:13
  • That's the point. I cannot debug it. In the console it just point to: at fromJson (localhost:8100/lib/ionic/js/ionic.bundle.js:9892:14) – FrancescoMussi Commented Jun 10, 2016 at 14:14
  • Open the json file, copy everything into chrome console and look at the errors, change file accordingly, rinse and repeat – KRONWALLED Commented Jun 10, 2016 at 14:17
Add a ment  | 

1 Answer 1

Reset to default 6

Removing char ',' at the end of key definition in your json. It make json parser try to read next char '}' as new key and error raised

本文标签: javascriptangulartranslate How to load static json filesStack Overflow