Настало время замечательных историй

Доклад о fbt Немного о самой технологии, как использовать, подводные камни.
FBT =>
FBT is a framework for internationalizing user interfaces in JavaScript
original ...Probably Facebook Translation?
However, even internally, we never use that terminology. It's always just referred to as "FBT".
import React, { useState } from "react";
import { Text } from "react-native";
import fbt from "fbt";
const App = () => {
const [userName] = useState("Alexandros");
return (
<Text>
<fbt desc="welcome message text">
Hello <fbt:param name="userName">{userName}</fbt:param>!
</fbt>
</Text>
);
};
_fbt.default._(
'Hello {userName}!',
[_fbt.default._param('userName', userName)],
{
hk: 'X60py',
},
)
module.exports = {
plugins: [
'babel-plugin-fbt-runtime',
['babel-plugin-fbt', {fbtEnumPath}],
],
presets: ['module:metro-react-native-babel-preset'],
};
import fbt from "fbt";
const MyFbt = (props) => ( // It don't work (
<fbt
author="ShowMeUrManager"
doNotExtract={false}
project="ui"
{...props}
/>
);
<fbt/> fbt(...)
<fbt:enum/> fbt.enum(...)
<fbt:param/> fbt.param(...)
<fbt:name/> fbt.name(...)
<fbt:same-param/> fbt.sameParam(...)
<fbt:plural/> fbt.plural(...)
<fbt:pronoun/> fbt.pronoun(...)
{
$$typeof: Symbol(react.element)
props: {content: Array(0: "Привет Alexandros!")}
type: ƒ FbtComponent(props)
_contents: ["Привет Alexandros!"]
_stringValue: null
key: null
ref: null
...
}
import { Alert } from 'react-native';
Alert.alert(
fbt('Confirmations', 'logout alert title').toString(),
fbt(
'Are you sure you want to Logout?',
'logout alert message text',
).toString(),
[
{
text: fbt('Yes', 'positive logout alert button text').toString(),
onPress: () => {},
},
{
text: fbt('Cancel', 'negative logout alert button text').toString(),
onPress: () => {},
style: 'cancel',
},
],
{ cancelable: false },
);
<fbt desc="welcome message text" project='ui'>
Hello <fbt:param name="userName">{userName}</fbt:param>!
</fbt>;
fbt(
`Hello ${fbt.param("userName", userName)})}!`,
"welcome message text",
{ project:"ui" }
);
<Text>
<fbt desc="styled text">
Is this
<Text onPress={cb} style={{ color: "red" }}>color</Text>
green?
</fbt>
</Text>
{
hashToText: { xxx: "Is this {=color} green?" },
desc: "styled text"
},
{
hashToText: { xxx: "color" },
desc: 'In the phrase: "Is this {=color} green?"'
}
<fbt desc="dublcated param example">
<fbt:name name="name" gender={GENDER}>
{name}
</fbt:name>
shared a link. Tell
<fbt:same-param name="name" />
you liked it.
</fbt>
NUMBER_ONE
: 1 товар в корзинеNUMBER_FEW
: 3 тоавра в корзинеNUMBER_MANY
: 10 товаров в корзинеGist: fbt.sh
<fbt:param/>
синтаксиса используем не документированый <FbtParam/>
синтаксис
@babel/plugin-transform-typescript