This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[0.63] Migrate localization library to fbt (#159)
Migrate localization library. We'd like to use `fbt` in react-native as well as react followed by the article https://medium.com/dooboolab/localizing-react-app-with-fbt-instead-of-i18n-90822e0cb373.
- Loading branch information
Showing
57 changed files
with
2,501 additions
and
1,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/// <reference types="react" /> | ||
|
||
declare namespace FBT { | ||
type $Values<T> = T[keyof T]; | ||
|
||
// https://github.com/facebookincubator/fbt/blob/e9c591f451dbfc91852e316869ae39ad41848c55/runtime/nonfb/GenderConst.js#L9-L23 | ||
interface GenderConst { | ||
NOT_A_PERSON: 0; | ||
FEMALE_SINGULAR: 1; | ||
MALE_SINGULAR: 2; | ||
FEMALE_SINGULAR_GUESS: 3; | ||
MALE_SINGULAR_GUESS: 4; | ||
MIXED_SINGULAR: 5; | ||
MIXED_PLURAL: 5; | ||
NEUTER_SINGULAR: 6; | ||
UNKNOWN_SINGULAR: 7; | ||
FEMALE_PLURAL: 8; | ||
MALE_PLURAL: 9; | ||
NEUTER_PLURAL: 10; | ||
UNKNOWN_PLURAL: 11; | ||
} | ||
|
||
interface IntlVariationsGender { | ||
GENDER_MALE: 1; | ||
GENDER_FEMALE: 2; | ||
GENDER_UNKNOWN: 3; | ||
} | ||
|
||
// https://github.com/facebookincubator/fbt/blob/e9c591f451dbfc91852e316869ae39ad41848c55/runtime/nonfb/IntlVariations.js#L9-L21 | ||
interface IntlVariations extends IntlVariationsGender { | ||
BITMASK_NUMBER: 28; | ||
BITMASK_GENDER: 3; | ||
NUMBER_ZERO: 16; | ||
NUMBER_ONE: 4; | ||
NUMBER_TWO: 8; | ||
NUMBER_FEW: 20; | ||
NUMBER_MANY: 12; | ||
NUMBER_OTHER: 24; | ||
} | ||
|
||
// https://github.com/facebookincubator/fbt/blob/c2d363a40b622d5aaf80ff1d249b38604fd869f6/transform/babel-plugin-fbt/FbtConstants.js#L22-L27 | ||
type PronounType = 'object' | 'possessive' | 'reflexive' | 'subject'; | ||
|
||
type IntlVariationsGenderValues = $Values<IntlVariationsGender>; | ||
|
||
interface IntlViewerContext { | ||
GENDER: IntlVariationsGenderValues; | ||
locale: string; | ||
} | ||
|
||
type IntlVariationsValues = $Values<IntlVariations>; | ||
type GenderConstValues = $Values<GenderConst>; | ||
|
||
type Translations = { [locale: string]: { [key: string]: string } }; | ||
|
||
interface Options { | ||
author?: string; | ||
common?: boolean; | ||
doNotExtract?: boolean; | ||
preserveWhitespace?: boolean; | ||
project?: string; | ||
subject?: IntlVariationsGenderValues; | ||
} | ||
|
||
interface PluralOptions { | ||
many?: string; | ||
showCount?: 'yes' | 'no' | 'ifMany'; | ||
name?: string; | ||
value?: any; | ||
} | ||
|
||
interface ParamOptions { | ||
gender?: IntlVariationsGenderValues; | ||
number?: number | true; | ||
} | ||
|
||
interface PronounOptions { | ||
human?: boolean; | ||
capitalize?: boolean; | ||
} | ||
|
||
type FbtResult = string; | ||
} | ||
|
||
declare namespace JSX { | ||
interface IntrinsicElements { | ||
fbt: { | ||
desc: string; | ||
children: React.ReactNode | React.ReactNode[]; | ||
} & FBT.Options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/// <reference path="globals.d.ts" /> | ||
|
||
declare module 'fbt' { | ||
export const GenderConst: FBT.GenderConst; | ||
export const IntlVariations: FBT.IntlVariations; | ||
export const IntlViewerContext: FBT.IntlViewerContext; | ||
|
||
// These exports (Fbt*) isn't real! It is only syntax abstraction | ||
// https://github.com/facebookincubator/fbt/blob/8607c1f2798ef18c6142a2cf1c5a9351c6d7df69/transform/babel-plugin-fbt/FbtUtil.js#L28-L40 | ||
export const FbtEnum: React.FC<{ | ||
'enum-range': Array<string> | { [enumKey: string]: string }; | ||
value: string; | ||
}>; | ||
export const FbtParam: React.FC< | ||
FBT.ParamOptions & { name: string; children: React.ReactNode } | ||
>; | ||
export const FbtPlural: React.FC< | ||
FBT.PluralOptions & { count: number; children: string } | ||
>; | ||
export const FbtPronoun: React.FC< | ||
FBT.PronounOptions & { | ||
type: FBT.PronounType; | ||
gender: FBT.GenderConstValues; | ||
} | ||
>; | ||
export const FbtName: React.FC< | ||
Omit<FBT.ParamOptions, 'gender'> & { | ||
name: string; | ||
gender: FBT.IntlVariationsGenderValues; | ||
children: React.ReactNode; | ||
} | ||
>; | ||
export const FbtSameParam: React.FC<{ | ||
name: string; | ||
}>; | ||
|
||
export interface Fbt { | ||
(source: string, desc: string, options?: FBT.Options): FBT.FbtResult; | ||
|
||
param( | ||
paramName: string, | ||
value: any, | ||
options?: FBT.ParamOptions, | ||
): FBT.FbtResult; | ||
sameParam(paramName: string): FBT.FbtResult; | ||
name(name: string, gender: FBT.IntlVariationsGenderValues): FBT.FbtResult; | ||
plural( | ||
singularPhrase: string, | ||
count: number, | ||
options?: FBT.PluralOptions, | ||
): FBT.FbtResult; | ||
enum< | ||
Range extends { [enumKey: string]: string }, | ||
RangeKeys extends keyof Range | ||
>( | ||
enumKey: RangeKeys, | ||
enumRange: Range, | ||
): FBT.FbtResult; | ||
enum(index: string, enumRange: Array<string>): FBT.FbtResult; | ||
pronoun( | ||
type: FBT.PronounType, | ||
gender: FBT.GenderConstValues, | ||
options: FBT.PronounOptions, | ||
): FBT.FbtResult; | ||
} | ||
|
||
export const init: (options: { translations: FBT.Translations, hooks: { getViewerContext: () => any} }) => void; | ||
|
||
export const fbt: Fbt; | ||
} | ||
|
||
declare namespace JSX { | ||
interface IntrinsicElements { | ||
fbt: any; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.