You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote a small implementation of the gettext concept recently and wanted to provide two new methods to the community. I was writing these in React Native, as shown below, and would be happy to incorporate the pure JS equivalents into this project for Hacktoberfest! 🎃🎃🎃
In short, the first method pboolgettext returns the plural form if a boolean is true or the singular form if the boolean is false. This is a case when no variables need to be inserted.
The second, pvboolgettext, does the same, but formats the plural message with variables.
/* * Returns the singular form of the message if a given boolean condition is true, otherwise the plural form. * * usage : pgettext(singularMessageId: string, pluralMessageId: string, b: boolean) * * @param singularMessageId <string> : the message ID to be used if the number of elements specified is zero * @param pluralMessageId <string> : the message ID to be sued if the number of elements specified is greater than zero * @param b <boolean> : a condition indicating if the singular message form should be displayed or not */pboolgettext(singularMessageId: string,pluralMessageId: string,b: boolean){if(typeofsingularMessageId==="undefined"||typeofsingularMessageId==="undefined"||typeofb==="undefined"){throw"pboolgettext: Invalid arguments";}returnb ? this.translations[singularMessageId] : this.translations[pluralMessageId];}/* * Returns the singular form of the message if a given boolean condition is true, otherwise the plural form formatted with variables. * * usage : pgettext(singularMessageId: string, pluralMessageId: string, b: boolean, value: any) * usage : pgettext(singularMessageId: string, pluralMessageId: string, b: boolean, values: [any, ... ,any]) * * Note : variables can be mixed string and number. * * @param singularMessageId <string> : the message ID to be used if the number of elements specified is zero * @param pluralMessageId <string> : the message ID to be sued if the number of elements specified is greater than zero * @param b <boolean> : a condition indicating if the singular message form should be displayed or not * @param v <any> : the variable or variables to insert into the plural string */pvboolgettext(singularMessageId: string,pluralMessageId: string,b: boolean, ...values){if(typeofsingularMessageId==="undefined"||typeofsingularMessageId==="undefined"||typeofb==="undefined"||typeofvalues==="undefined"){throw"pvboolgettext: Invalid arguments";}if(b){returnthis.translations[singularMessageId];}returnthis.vngettext(pluralMessageId, ...values);}
The text was updated successfully, but these errors were encountered:
I wrote a small implementation of the gettext concept recently and wanted to provide two new methods to the community. I was writing these in React Native, as shown below, and would be happy to incorporate the pure JS equivalents into this project for Hacktoberfest! 🎃🎃🎃
In short, the first method pboolgettext returns the plural form if a boolean is true or the singular form if the boolean is false. This is a case when no variables need to be inserted.
The second, pvboolgettext, does the same, but formats the plural message with variables.
The text was updated successfully, but these errors were encountered: