Javascript, language files, configuration

Posted by johnnyArt on Stack Overflow See other posts from Stack Overflow or by johnnyArt
Published on 2010-03-14T14:19:40Z Indexed on 2010/03/14 14:25 UTC
Read the original article Hit count: 319

I'm building a form validation script for one of my sites, and I thought I'd make the error messages international, meaning that depending on the users language I'd give such or such response.

What would the best approach be, for loading a configuration file inside of my class? Right now I'm using the following structure for a single language:

const config = {
    'errorName'  : 'error message',
    'errorName2' : 'error message',
    'errorName2' : 'error message'
}

And calling it like this of course: config['errorName']. But I don't know how to load those variables from a file, let's say 'lang/en.js'

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about configuration