Better i18n support

Better i18n support

specially Arabic
Quick read
Mar 31, 2020 8:35 AM (2 years 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.

My Newsletter

I send out an email every so often about cool stuff I'm working on or launching. If you dig, go ahead and sign up!

No spam, only goldden nuggets 💎


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