How to use the ember-intl.intl function in ember-intl

To help you get started, weā€™ve selected a few ember-intl examples, based on popular ways it is used in public projects.

github ember-intl / decorators / addon / intl.ts View on Github external
export default (decoratorWithParams(function intl<Target extends object>(
  target: Target,
  key: keyof Target,
  desc: PropertyDescriptor & { initializer: () => GetterFn },
  dependentKeys: string[] = []
) {
  const value: GetterFn = desc.value;
  const initializer: () => GetterFn = desc.initializer;
  delete desc.value;
  delete desc.initializer;

  const cp = intlMacro(...dependentKeys, function(
    intl: IntlService, // eslint-disable-line no-shadow
    propertyKey: string
  ) {
    const fn: GetterFn = value || initializer.call(this);
    assert(
      `@intl: You need to decorate a function, but you decorated '${fn}'.`,
      typeof fn === 'function'
    );

    return fn.call(this, intl, propertyKey);
  });

  // @ts-ignore
  return cp(target, key, desc);
}) as unknown) as ((
  ...args: Parameters<typeof intlMacro>