#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2017
    Posts
    2
    Rep Power
    0

    Question Javascript - doubt about ES6 ( i think) [INTL-React]


    Hello, I have this piece of code that I don' understand (taken from a intl-react translation)
    Code:
    const translations = globSync('./build/lang/*.json')
        .map((filename) => [
            path.basename(filename, '.json'),
            readFileSync(filename, 'utf8'),
        ])
        .map(([locale, file]) => [locale, JSON.parse(file)])
        .reduce((collection, [locale, messages]) => {
            collection[locale] = messages;
            return collection;
        }, {});
    Code:
    app.get('/', (req, res) => {
        let locale   = req.query.locale || 'en-US';
        let messages = translations[locale];
    
        if (!messages) {
            return res.status(404).send('Locale is not supported.');
        }
    what is translations? a function? a variable? and why is the square bracket used in the parts I bolded?
    Thanks for taking the time to reading this >)
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2017
    Posts
    2
    Rep Power
    0
    it doesn't show... the bolded part were
    Code:
    let messages = translations[locale];
    and
    Code:
    [
            path.basename(filename, '.json'),
            readFileSync(filename, 'utf8'),
        ]

IMN logo majestic logo threadwatch logo seochat tools logo