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
You will need to have Redis installed in order for caching to work properly.
If you do not plan to use Redis, then set redis: false as an option.
Google Application Credentials
You will also need Google Application Credentials, and you will need to set them as environment variables (e.g. GOOGLE_APPLICATION_CREDENTIALS=/home/user/Downloads/service-account-file.json).
Implement Mandarin and pass it an instance of i18n
constMandarin=require('mandarin');constI18N=require('@ladjs/i18n');consti18n=newI18N();// you can also pass a custom `logger` option (it defaults to `console`)constmandarin=newMandarin({// REQUIRED:
i18n
// OPTIONAL:// logger: console,// OPTIONAL (see index.js for defaults):// redis: ...// OPTIONAL (see index.js for defaults):// redisMonitor: ...// OPTIONAL:// see all commented options from this following link:// <https://googleapis.dev/nodejs/translate/5.0.1/v2_index.js.html>//// clientConfig: {},// OPTIONAL (see index.js for defaults):// Files to convert from `index.md` to `index-es.md`// Or `README.md` to `README-ZH.md` for example// <https://github.com/sindresorhus/globby>//// markdown: ... (note we expose `Mandarin.DEFAULT_PATTERNS` for you)});//// Translate Phrases//// with async/await(async()=>{try{awaitmandarin.translate();}catch(err){console.log(err);}})();// with promises and then/catchmandarin.translate().then(()=>{console.log('done');}).catch(console.error);// with callbacksmandarin.translate(err=>{if(err)throwerr;console.log('done');});//// Translate Markdown Files//// with async/await(async()=>{try{awaitmandarin.markdown();}catch(err){console.log(err);}})();// with promises and then/catchmandarin.markdown().then(()=>{console.log('done');}).catch(console.error);// with callbacksmandarin.markdown(err=>{if(err)throwerr;console.log('done');});
This assumes that you have locale files already and a default locale file (e.g. ./locales/en.json with phrases that need translated to other languages you support). Based off the defaults from i18n, you would automatically get your en.json file translated to the locales es (Spanish) and zh (Chinese).