import { Context } from '@eggjs/core'; export default class I18nContext extends Context { /** * get current request locale * @member Context#locale * @return {String} lower case locale string, e.g.: 'zh-cn', 'en-us' */ get locale(): string; set locale(l: string); /** * `ctx.__` 的别名。 * @see {@link Context#__} * @function Context#gettext */ gettext(key: string, value?: any, ...args: any[]): string; /** * 如果开启了 I18n 多语言功能,那么会出现此 API,通过它可以获取到当前请求对应的本地化数据。 * * 详细使用说明,请查看 {@link I18n} * - `ctx.__ = function (key, value[, value2, ...])`: 类似 `util.format` 接口 * - `ctx.__ = function (key, values)`: 支持数组下标占位符方式,如 * - `__` 的别名是 `gettext(key, value)` * * > NOTE: __ 是两个下划线哦! * @function Context#__ * @example * ```js * ctx.__('{0} {0} {1} {1}'), ['foo', 'bar']) * ctx.gettext('{0} {0} {1} {1}'), ['foo', 'bar']) * => * foo foo bar bar * ``` * ##### Controller 下的使用示例 * * ```js * module.exports = function* () { * this.body = { * message: this.__('Welcome back, %s!', this.user.name), * // 或者使用 gettext,如果觉得 __ 不好看的话 * // message: this.gettext('Welcome back, %s!', this.user.name), * user: this.user, * }; * }; * ``` * * ##### View 文件下的使用示例 * * ```html *