Internationalization v4.1 - Beginner - How to call select format


#1

How to call the select format provided in the v4.1
Link to the documentation: https://adonisjs.com/docs/4.1/internationalization#_select_format

What I want it to return is when I pass ‘male’, I get ’He will respond shortly’ and upon passing ‘female’, I get 'she will respond shortly’

Here is the code what I thought would work:

messages.json

{
    "greeting": "{ gender,select } will respond shortly"
}

PostController.js

Formats.add('gender','select', {
                male: 'he',
                female: 'she',
                other: 'they'
            })

const test = Antl.formatMessage (
                'messages.greeting', 
                { gender: 'male' }, //this 'male' should return 'he'
                [
                    Formats.pass('gender','select')
                ]
            )
console.log(test)

Upon running this code, I am getting this error:


#2

Alas, I got it working. I am not sure if it is the right way but it does the job.

The FormatJS.io uses space separation in querying within .JSON file

messages.json

{
    "greeting": "{ gender, select, male {He} female {She} other {They} } will respond shortly"
}

PostController.js

const test = Antl.formatMessage (
            'messages.greeting', 
            { gender: 'female' }
        )