Tannin Default Fallback

node v8.17.0
version: master
endpointsharetweet
const Tannin = require( 'tannin' ); const i18n = new Tannin( { default: { '': { lang: 'fr', }, 'Why?': [ 'Pourquoi?' ], }, mydomain: { '': { lang: 'fr', }, 'When?': [ 'Quand?' ], }, }, { onMissingKey() { i18n._missingKey = true; } } ); i18n.dcnpgettext = function( ...args ) { const result = Tannin.prototype.dcnpgettext.apply( this, args ); if ( this._missingKey ) { delete this._missingKey; return Tannin.prototype.dcnpgettext.call( this, 'default', ...args.slice( 1 ) ); } return result; }; console.log( i18n.dcnpgettext( 'mydomain', undefined, 'When?' ) ); console.log( i18n.dcnpgettext( 'mydomain', undefined, 'Why?' ) );
Loading…

no comments

    sign in to comment