What This Adds In Cloud Code
- Accesses site copywriting keys from server logic.
- Supports locale override and interpolation variables.
- Keeps locale text out of hardcoded JS.
Quick Start
js
const I18n = require('i18n');
const label = I18n.t('emails.welcome.subject', { locale: 'en' });API
| Function | Params | Returns | Notes |
|---|---|---|---|
t(key, variables) | key: string, variables?: object | string | Reads locale and default from variables; interpolates other keys. |
Practical Example
js
const I18n = require('i18n');
const Mail = require('mail');
Mail.send({
to: request.params.to,
subject: I18n.t('emails.password_reset.subject', { locale: request.params.locale, default: 'Reset password' }),
text: I18n.t('emails.password_reset.body', { locale: request.params.locale, name: request.params.name })
});Failure Modes & Gotchas
- Missing keys depend on translation service fallback behavior.
- Always pass
defaultfor user-visible critical text.