How to use the i18next.getFixedT function in i18next

To help you get started, we’ve selected a few i18next examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github i18next / i18next / test / typescript / i18next-tests.ts View on Github external
)

// with only callback
i18next.init((err: any, t: i18next.TranslationFunction) => {
  if (err) {
    console.log('something went wrong loading', err)
    return
  }
  t('key') // -> same as i18next.t
})

const v: string = i18next.t('my.key')
const a: boolean = i18next.exists('my.key')

// fix language to german
const de = i18next.getFixedT('de')
const z: string = de('myKey')

// or fix the namespace to anotherNamespace
const anotherNamespace = i18next.getFixedT(null, 'anotherNamespace')
const x: string = anotherNamespace('anotherNamespaceKey') // no need to prefix ns i18n.t('anotherNamespace:anotherNamespaceKey');

i18next.changeLanguage('en', (err: any, t: i18next.TranslationFunction) => {
  if (err) {
    console.log('something went wrong loading', err)
    return
  }
  t('key') // -> same as i18next.t
})

i18next.loadNamespaces('myNamespace', (err: any, t: i18next.TranslationFunction) => {
  /* resources have been loaded */
github i18next / i18next / test / typescript / i18next-tests.ts View on Github external
if (err) {
    console.log('something went wrong loading', err)
    return
  }
  t('key') // -> same as i18next.t
})

const v: string = i18next.t('my.key')
const a: boolean = i18next.exists('my.key')

// fix language to german
const de = i18next.getFixedT('de')
const z: string = de('myKey')

// or fix the namespace to anotherNamespace
const anotherNamespace = i18next.getFixedT(null, 'anotherNamespace')
const x: string = anotherNamespace('anotherNamespaceKey') // no need to prefix ns i18n.t('anotherNamespace:anotherNamespaceKey');

i18next.changeLanguage('en', (err: any, t: i18next.TranslationFunction) => {
  if (err) {
    console.log('something went wrong loading', err)
    return
  }
  t('key') // -> same as i18next.t
})

i18next.loadNamespaces('myNamespace', (err: any, t: i18next.TranslationFunction) => {
  /* resources have been loaded */
})
i18next.loadNamespaces(
  ['myNamespace1', 'myNamespace2'],
  (err: any, t: i18next.TranslationFunction) => {
github pnp / PnP / Solutions / Business.StarterIntranet / app / src / components / TranslationControl / TranslationControlViewModel.ts View on Github external
// Reset internal states
        this.wait(true);
        this.isError(false);

        const targetLanguage: string = this.selectedLanguage();

        const peerWebAbsoluteUrl = _spPageContextInfo.siteAbsoluteUrl + "/" +  targetLanguage.toLowerCase();
        const peerWebServerRelativeUrl = _spPageContextInfo.siteServerRelativeUrl + "/" +  targetLanguage.toLowerCase();

        const peerWeb = new Web(peerWebAbsoluteUrl);
        const currentWeb = new Web(_spPageContextInfo.webAbsoluteUrl);

        // Build the destination file URL

        // Get the Pages library name in the target language
        const i18nTargetLanguage = i18n.getFixedT(targetLanguage.toLowerCase());
        const pagesLibraryName = i18nTargetLanguage("pagesLibraryName");

        const regex = "\/" + pagesLibraryName + "\/(.*)\/.*\.aspx";
        const regexInstance = new RegExp(regex, "g");
        const currentPageFolder = regexInstance.exec(this.currentPageUrl);
        const folderName = currentPageFolder ? ("/" + currentPageFolder[1] + "/") : "/";

        const fileName = this.inputDestinationFileName() + ".aspx";
        const destinationFilePath = peerWebServerRelativeUrl + "/" + pagesLibraryName + folderName + fileName;

        const web = new Web(_spPageContextInfo.webAbsoluteUrl);

        this.ensurePageGuid().then(() => {

            // Copy the page in the Pages library of the peer web with the new language
            // Note: during the copy operation, all original metadata are retained by default
github celo-org / celo-monorepo / packages / notification-service / src / firebase.ts View on Github external
export function getTranslatorForAddress(address: string) {
  const registration = registrations[address]
  const language = registration && registration.language
  // Language is set and i18next has the proper config
  if (language) {
    console.info(`Language resolved as ${language} for user address ${address}`)
    return i18next.getFixedT(language)
  }
  // If language is not supported falls back to env.DEFAULT_LOCALE
  console.info(`Users ${address} language is not set, valid or supported`)
  return i18next.t.bind(i18next)
}
github VoxaAI / voxa / test / alexa / AlexaReply.spec.ts View on Github external
beforeEach(() => {
    const app = new VoxaApp({ views });
    const skill = new AlexaPlatform(app);
    renderer = new Renderer({ views, variables });
    event = new AlexaEvent(rb.getIntentRequest("SomeIntent"));
    event.renderer = renderer;
    event.t = i18n.getFixedT(event.request.locale);
    event.platform = skill;
    reply = new AlexaReply();
  });
github VoxaAI / voxa / test / Renderer.spec.ts View on Github external
beforeEach(() => {
    voxaApp = new VoxaApp({ views });
    renderer = new Renderer({ views, variables });
    rawEvent = rb.getIntentRequest("SomeIntent");
    event = new AlexaEvent(rawEvent);
    event.platform = new AlexaPlatform(voxaApp);
    event.t = i18n.getFixedT("en-US");

    statesDefinition = {
      LaunchIntent: { to: "endState" },
      SomeIntent: { to: "endState" },
      endState: { ask: "ExitIntent.Farewell", to: "die" },
      initState: { to: "endState" },
      secondState: { to: "initState" },
      thirdState: () => Promise.resolve({ to: "endState" }),
    };
  });
github crimx / ext-saladict / src / content / components / MenuBar / SearchBox.stories.tsx View on Github external
.add('SearchBox', () => {
    const [text, setText] = useState('text')
    return (
       {
          setText(text)
          action('Input')(text)
        }}
        onSearch={text => {
          setText(text)
          action('Search')(text)
        }}
        onHeightChanged={action('Height Changed')}
      />
    )
  })
github zhaotoday / react.js / src / utils / i18n.js View on Github external
getT (ns) {
    return i18next.getFixedT(this.lng, ns || this.ns)
  }
}
github javallone / regexper-static / src / components / LocaleSwitcher / index.js View on Github external
{ Object.keys(locales).map(locale => (
            <option value="{">{ i18n.getFixedT(locale)('/displayName') }</option>
          )) }
github crimx / ext-saladict / src / content / components / MenuBar / Profiles.stories.tsx View on Github external
.add('Profiles', () =&gt; {
    const profiles = Array.from(Array(5)).map((_, i) =&gt; ({
      id: `profile${i + 1}`,
      name: `Profile${i + 1}`
    }))

    const profilesOption = profiles.reduce((o, p) =&gt; {
      o[p.name] = p.id
      return o
    }, {})
    return (
      
    )
  })