NocoBase Plugin Translation Hook (client-v2/locale.ts)

nocobase · packages/plugins/@nocobase-example/plugin-settings-page/src/client-v2/locale.ts · typescript · Apache-2.0
ui, fw:react, tag:knn-classified, tag:nocobase, tag:plugin

Provides React hook and expression function for localized strings in NocoBase plugin settings pages using flow engine context.

// Source: https://github.com/nocobase/nocobase | License: Apache-2.0
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * This file is part of the NocoBase (R) project.
 * Copyright (c) 2020-2024 NocoBase Co., Ltd.
 * Authors: NocoBase Team.
 *
 * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
 * For more information, please refer to: https://www.nocobase.com/agreement.
 */

import { tExpr as _tExpr, useFlowEngine } from '@nocobase/flow-engine';
// @ts-ignore
import pkg from './../../package.json';

export function useT() {
  const engine = useFlowEngine();
  return (str: string) => engine.context.t(str, { ns: [pkg.name, 'client'] });
}

export function tExpr(key: string) {
  return _tExpr(key, { ns: [pkg.name, 'client'] });
}

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key