Skip to main content

Localization

  • useSafeTranslation hook

    • Pass in the "filename / namespace" as the parameter  

      • const { t } = useSafeTranslation(TranslationFiles.RecycleBin)
      • All "filenames / namespaces" are stored in the enum TranslationFiles (which currently can be found in the same file as the useSafeTranslation hook)

       

  • Define string lookup keys as enums

    • export enum RecycleBinTKeys {
          Name = 'name',
          DateDeleted = 'dateDeleted',
          Path = 'path',
          Purge = 'purge',
          PurgeForever = 'purgeForever',
          Restore = 'restore',
          Cancel = 'cancel',
          ForceCheckIn = 'forceCheckIn',
          PurgeConfirmMsg = 'purgeConfirmMsg',
          AreYouSure = 'areYouSure',
          EmptyMsg = 'emptyMsg',
          PageTitle = 'pageTitle',
      }

    • Need to be single strings with no spaces.

    • enum name should be match the name of the namespace it will be used for, and have TKeys appended to the end.
    • All TKey enums are in currently in the same file as ththe useSafeTranslation hook.
  • Use the "t" method

    • ​t(RecycleBinTKeys.Name)

    • If the key doesn't exist it will be added

    • Must run the code and navigate to location

  • locales folder contains all the string translations

    • Namespace matches the name of the json file

  

  • If rendering of page needs to wait for the json file to be loaded in use the ready value from useSafeTranslation, around the return value. (May need if page doesn't load and you get white screen) 
    • const {t, ready } = useSafeTranslation(TranslationFiles.RecycleBin);
    • return !ready ? null : ( /* all your jsx here */)
    • This is striked out becuase we haven'thave neednot needed to do this. We're not sure what fixed the orginaloriginal issue but it's not needed anymore, but I've left this here just in case we run into it again in the future.

Plurals

see i18n documentation here. Plurals are useful when the copy needs to change slightly when you have multiple items, for example, when you are deleting 2 items instead of one, you want to add an 's' to the end of a word to make it plural.

Nesting

see i18n documentation here. Nesting is useful when you need pass multiple values into the copy, for example, when you the copy indicates how many file uploads and form fills are in a document request that is assigned to you.