react-i18next#TFunction TypeScript Examples

The following examples show how to use react-i18next#TFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BuildGameModel.ts    From longwave with MIT License 6 votes vote down vote up
export function BuildGameModel(
  gameState: GameState,
  setGameState: (newState: Partial<GameState>) => void,
  localPlayerId: string,
  tSpectrumCards: TFunction<"spectrum-cards">,
  setPlayerName: (newName: string) => void
): GameModel {
  const clueGiver = gameState.players[gameState.clueGiver]
    ? {
        ...gameState.players[gameState.clueGiver],
        id: gameState.clueGiver,
      }
    : null;

  type SpectrumCard = [string, string];
  const basicCards = tSpectrumCards("basic", {
    returnObjects: true,
  }) as SpectrumCard[];
  const advancedCards = tSpectrumCards("advanced", {
    returnObjects: true,
  }) as SpectrumCard[];
  const AllCards = [...basicCards, ...advancedCards];
  const spectrumDeck = getSeededDeck(gameState.deckSeed, AllCards);

  return {
    gameState,
    localPlayer: {
      ...gameState.players[localPlayerId],
      id: localPlayerId,
    },
    clueGiver,
    spectrumCard: spectrumDeck[gameState.deckIndex % spectrumDeck.length],
    setGameState,
    setPlayerName,
  };
}
Example #2
Source File: GameState.ts    From longwave with MIT License 6 votes vote down vote up
export function TeamName(team: Team, t: TFunction<string>) {
  if (team === Team.Left) {
    return t("gamestate.left_brain");
  }
  if (team === Team.Right) {
    return t("gamestate.right_brain");
  }
  return t("gamestate.the_player");
}
Example #3
Source File: NewGame.ts    From longwave with MIT License 6 votes vote down vote up
export function NewTeamGame(
  players: PlayersTeams,
  startPlayer: string,
  gameState: GameState,
  tSpectrumCards: TFunction<"spectrum-cards">
): Partial<GameState> {
  const initialScores: Partial<GameState> = {
    leftScore: 0,
    rightScore: 0,
  };

  const playerTeam = players[startPlayer].team;
  if (playerTeam === Team.Left) {
    initialScores.rightScore = 1;
  } else {
    initialScores.leftScore = 1;
  }

  return {
    ...NewRound(startPlayer, gameState, tSpectrumCards),
    ...initialScores,
    previousTurn: null,
    gameType: GameType.Teams,
  };
}
Example #4
Source File: NewRound.ts    From longwave with MIT License 6 votes vote down vote up
export function NewRound(
  playerId: string,
  gameState: GameState,
  tSpectrumCards: TFunction<"spectrum-cards">
): Partial<GameState> {
  const gameModel = BuildGameModel(
    gameState,
    () => {},
    playerId,
    tSpectrumCards,
    () => {}
  );

  const newState: Partial<GameState> = {
    clueGiver: playerId,
    roundPhase: RoundPhase.GiveClue,
    deckIndex: gameState.deckIndex + 1,
    turnsTaken: gameState.turnsTaken + 1,
    spectrumTarget: RandomSpectrumTarget(),
  };

  if (gameModel.clueGiver !== null) {
    newState.previousTurn = {
      spectrumCard: gameModel.spectrumCard,
      spectrumTarget: gameState.spectrumTarget,
      clueGiverName: gameModel.clueGiver.name,
      clue: gameState.clue,
      guess: gameState.guess,
    };
  }

  return newState;
}
Example #5
Source File: CalculatorHeader.tsx    From nuzlocke with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
export function getDesc(result: Result, t: TFunction): string {
  try {
    return result?.fullDesc() || t('no_move_selected');
  } catch (e) {
    if ((e as Error).message === 'damage[damage.length - 1] === 0.') {
      return `${result.attacker.name} ${result.move.name} vs ${result.defender.name}: 0 - 0%`;
    }
    return t('invalid_calculation');
  }
}
Example #6
Source File: AdditionalInfo.tsx    From frontend with Apache License 2.0 6 votes vote down vote up
function getLicense(project_license: string | undefined, t: TFunction<"translation", undefined>): string | undefined {
  if (!project_license) {
    return undefined
  }

  if (project_license?.startsWith('LicenseRef-proprietary=')) {
    return project_license?.replace(/LicenseRef-proprietary=/, '')
  }
  if (project_license?.startsWith('LicenseRef-proprietary')) {
    return t('proprietary')
  }

  const splitLicense = project_license.split(' ')
  if (splitLicense.length <= 1) {
    return (
      spdxLicenseList[project_license]?.name ?? project_license ?? t('unknown')
    )
  }

  return splitLicense
    .map((license) => {
      if (spdxLicenseList[license]) {
        return spdxLicenseList[license].name
      }
    })
    .join(', ')
}
Example #7
Source File: Category.ts    From frontend with Apache License 2.0 6 votes vote down vote up
export function categoryToName(category: Category, t: TFunction<"translation", undefined>): string {
  switch (category) {
    case Category.AudioVideo:
      return t('audio-and-video')
    case Category.Development:
      return t('developer-tools')
    case Category.Game:
      return t('games')
    case Category.Graphics:
      return t('graphics-and-photography')
    case Category.Network:
      return t('networking')
    case Category.Office:
      return t('productivity')
    case Category.Utility:
      return t('utilities')
    default:
      return category as string
  }
}
Example #8
Source File: useCallWikiInitialization.ts    From TidGi-Desktop with Mozilla Public License 2.0 6 votes vote down vote up
export async function callWikiInitialization(
  newWorkspaceConfig: INewWorkspaceConfig,
  wikiCreationMessageSetter: (m: string) => void,
  t: TFunction<'translation'>,
  gitUserInfo: IGitUserInfos | undefined,
): Promise<void> {
  wikiCreationMessageSetter(t('Log.InitializeWikiGit'));
  const newWorkspace = await window.service.wikiGitWorkspace.initWikiGitTransaction(newWorkspaceConfig, gitUserInfo);
  if (newWorkspace === undefined) {
    throw new Error('newWorkspace is undefined');
  }
  // start wiki on startup, or on sub-wiki creation
  wikiCreationMessageSetter(t('Log.InitializeWorkspaceView'));
  /** create workspace from workspaceService to store workspace configs, and create a BrowserView to actually display wiki web content from viewService */
  await window.service.workspaceView.initializeWorkspaceView(newWorkspace, { isNew: true });
  await window.service.workspaceView.setActiveWorkspaceView(newWorkspace.id);
  // wait for wiki to start and close the window now.
  await window.remote.closeCurrentWindow();
}
Example #9
Source File: useIndicator.ts    From TidGi-Desktop with Mozilla Public License 2.0 6 votes vote down vote up
export function updateErrorInWhichComponentSetterByErrorMessage(
  t: TFunction<'translation', undefined>,
  message: string,
  errorInWhichComponentSetter: (errors: IErrorInWhichComponent) => void,
): void {
  if (message.includes(t('AddWorkspace.PathNotExist').replace(/".*"/, ''))) {
    errorInWhichComponentSetter({ parentFolderLocation: true, wikiFolderLocation: true });
  }
  if (message.includes(t('AddWorkspace.CantCreateFolderHere').replace(/".*"/, ''))) {
    errorInWhichComponentSetter({ parentFolderLocation: true });
  }
  if (message.includes(t('AddWorkspace.WikiExisted').replace(/".*"/, ''))) {
    errorInWhichComponentSetter({ wikiFolderName: true });
  }
  if (message.includes(t('AddWorkspace.ThisPathIsNotAWikiFolder').replace(/".*"/, ''))) {
    errorInWhichComponentSetter({ wikiFolderName: true, wikiFolderLocation: true });
  }
}
Example #10
Source File: hooks.ts    From TidGi-Desktop with Mozilla Public License 2.0 6 votes vote down vote up
export function getUpdaterMessage(status: IUpdaterMetaData['status'], info: IUpdaterMetaData['info'], t: TFunction<'translation'>): string {
  if (status === IUpdaterStatus.checkingFailed) {
    return `${t('ErrorMessage')} ${info?.errorMessage ?? '-'}`;
  }
  if (status === IUpdaterStatus.updateAvailable) {
    return `v${info?.version ?? '-'}`;
  }
  return '';
}
Example #11
Source File: vaults.ts    From interbtc-ui with Apache License 2.0 5 votes vote down vote up
getVaultStatusLabel = (
  vaultExt: VaultExt<BitcoinUnit>,
  currentActiveBlockNumber: number,
  liquidationThreshold: Big,
  secureCollateralThreshold: Big,
  btcToCollateralTokenRate: BTCToCollateralTokenRate,
  t: TFunction
): string => {
  const settledCollateralization = getCollateralization(
    vaultExt.backingCollateral,
    vaultExt.issuedTokens,
    btcToCollateralTokenRate
  );

  // Default to active
  let statusLabel = t('dashboard.vault.active');
  if (settledCollateralization) {
    if (settledCollateralization.lt(liquidationThreshold)) {
      statusLabel = t('dashboard.vault.liquidation');
    }
    if (settledCollateralization.lt(secureCollateralThreshold)) {
      statusLabel = t('dashboard.vault.undercollateralized');
    }
  }
  // Should only display bannedUntil status if current active block number < the bannedUntil block number
  // Otherwise, should not show this status.
  if (vaultExt.bannedUntil && currentActiveBlockNumber < vaultExt.bannedUntil) {
    statusLabel = t('dashboard.vault.banned_until', { blockHeight: vaultExt.bannedUntil });
  }
  if (vaultExt.status === VaultStatusExt.Inactive) {
    statusLabel = t('dashboard.vault.inactive');
  }
  if (vaultExt.status === VaultStatusExt.CommittedTheft) {
    statusLabel = t('dashboard.vault.theft');
  }
  if (vaultExt.status === VaultStatusExt.Liquidated) {
    statusLabel = t('dashboard.vault.liquidated');
  }

  return statusLabel;
}