Better i18n support
Better i18n support
specially Arabic
Mar 31, 2020 8:35 AM (5 months ago)

Working with different languages can be challenging. Specially languages that have multiple references to different things like gender.

Languages like Arabic reference words as male or female depends on the context and grammar.
In English when we refer to gender we say (I'll till her / him) in Arabic we say (سوف اقول له) for male, (سوف اقول لها) for female.

Managing this in a template using if statements can be tedious.

# This little snippet may help you

/**
* Gender reference
* defaults to male refernce if gender is undefined
**/

function gr(gender, maleRef, femaleRef) {

        if(gender == 'female') {
          return femaleRef;
        }

        return maleRef;
}
/**
* Usage
**/

// returns [I'll tell him.] if gender = male
const statement = `I'll tell ${gr(this.gender, 'him', 'her')}.`;


// or use it to interchage the whole statement
const statement = gr(this.gender, 'سوف اقول له', 'سوف اقول لها');

# Simple right.

التعليقات

Ahmed Nagi - Powerd By Vuepress. hosted with GitHub and Netlify.