index.d.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { ReactElement, ReactNode } from 'react';
  2. export interface TranslationQuery {
  3. [name: string]: any;
  4. }
  5. export declare type Translate = <T = string>(i18nKey: string | TemplateStringsArray, query?: TranslationQuery | null, options?: {
  6. returnObjects?: boolean;
  7. fallback?: string | string[];
  8. default?: string;
  9. ns?: string;
  10. }) => T;
  11. export interface I18n {
  12. t: Translate;
  13. lang: string;
  14. }
  15. export interface I18nProviderProps {
  16. lang?: string;
  17. namespaces?: Record<string, I18nDictionary>;
  18. children?: ReactNode;
  19. config?: I18nConfig;
  20. }
  21. export interface TransProps {
  22. i18nKey: string;
  23. components?: ReactElement[] | Record<string, ReactElement>;
  24. values?: TranslationQuery;
  25. fallback?: string | string[];
  26. defaultTrans?: string;
  27. ns?: string;
  28. }
  29. export declare type PageValue = string[] | ((context: object) => string[]);
  30. export declare type LocaleLoader = (language: string | undefined, namespace: string) => Promise<I18nDictionary>;
  31. export interface I18nConfig {
  32. defaultLocale?: string;
  33. locales?: string[];
  34. loadLocaleFrom?: LocaleLoader;
  35. localesToIgnore?: string[];
  36. pages?: Record<string, PageValue>;
  37. logger?: I18nLogger;
  38. loggerEnvironment?: 'node' | 'browser' | 'both';
  39. staticsHoc?: Function;
  40. extensionsRgx?: string;
  41. loader?: boolean;
  42. logBuild?: boolean;
  43. revalidate?: number;
  44. pagesInDir?: string;
  45. interpolation?: {
  46. format?: Function;
  47. prefix: string;
  48. suffix: string;
  49. };
  50. keySeparator?: string | false;
  51. nsSeparator?: string | false;
  52. defaultNS?: string;
  53. }
  54. export interface LoaderConfig extends I18nConfig {
  55. locale?: string;
  56. router?: {
  57. locale: string;
  58. };
  59. pathname?: string;
  60. skipInitialProps?: boolean;
  61. loaderName?: string;
  62. isLoader?: boolean;
  63. [key: string]: any;
  64. }
  65. export interface LoggerProps {
  66. namespace: string | undefined;
  67. i18nKey: string;
  68. }
  69. export interface I18nLogger {
  70. (context: LoggerProps): void;
  71. }
  72. export interface I18nDictionary {
  73. [key: string]: string | I18nDictionary;
  74. }
  75. export interface DynamicNamespacesProps {
  76. dynamic?: LocaleLoader;
  77. namespaces?: string[];
  78. fallback?: ReactNode;
  79. children?: ReactNode;
  80. }
  81. declare global {
  82. module NodeJS {
  83. interface Global {
  84. i18nConfig: LoaderConfig;
  85. }
  86. }
  87. interface Window {
  88. i18nConfig: LoaderConfig;
  89. }
  90. }