Skip to content

Commit 056f6f4

Browse files
committed
refactor: rename I18N
1 parent d17bc18 commit 056f6f4

8 files changed

Lines changed: 47 additions & 48 deletions

File tree

localize/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ I18n.translations = {
2323
en,
2424
};
2525

26-
export { I18n };
26+
export { I18n as AppI18n };

navigation/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from "../types";
2424
import LinkingConfiguration from "./LinkingConfiguration";
2525
import TestStatisticsScreen from "@/screens/TestStatisticsScreen";
26-
import { I18n } from "@/localize";
26+
import { AppI18n } from "@/localize";
2727

2828
export default function Navigation({
2929
colorScheme,
@@ -86,7 +86,7 @@ function BottomTabNavigator() {
8686
name="TestRun"
8787
component={TestRunScreen}
8888
options={({ navigation }: RootTabScreenProps<"TestRun">) => ({
89-
title: I18n.t("testRun.title"),
89+
title: AppI18n.t("testRun.title"),
9090
tabBarIcon: ({ color }) => <TabBarIcon name="code" color={color} />,
9191
headerRight: () => (
9292
<Pressable
@@ -109,7 +109,7 @@ function BottomTabNavigator() {
109109
name="TestStatistics"
110110
component={TestStatisticsScreen}
111111
options={({ navigation }: RootTabScreenProps<"TestStatistics">) => ({
112-
title: I18n.t("testStatistics.title"),
112+
title: AppI18n.t("testStatistics.title"),
113113
tabBarIcon: ({ color }) => <TabBarIcon name="code" color={color} />,
114114
headerRight: () => (
115115
<Pressable
@@ -132,7 +132,7 @@ function BottomTabNavigator() {
132132
name="TestConfig"
133133
component={TestConfigScreen}
134134
options={{
135-
title: I18n.t("testConfig.title"),
135+
title: AppI18n.t("testConfig.title"),
136136
tabBarIcon: ({ color }) => <TabBarIcon name="code" color={color} />,
137137
}}
138138
/>

screens/TestConfigScreen/components/ConfigList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createAppFolderIfNeeded, initDefaultFilesIfNeeded } from "@/storage/fil
66
import { userSettingsStore, UserSetting } from "@/store/UserSettings";
77
import { observer } from "mobx-react";
88
import { testStatisticsStore } from "@/store/TestStatistics";
9-
import { I18n } from "@/localize";
9+
import { AppI18n } from "@/localize";
1010
import { useTheme } from "@react-navigation/native";
1111

1212
export const ConfigList = observer(() => (
@@ -58,7 +58,7 @@ function InternalConfigList({ userSettings }: { userSettings: UserSetting }) {
5858
<View style={styles.container}>
5959
<View style={styles.list}>
6060
<View style={styles.item}>
61-
<Text>{I18n.t("testConfig.saveAllDataToDevice")}</Text>
61+
<Text>{AppI18n.t("testConfig.saveAllDataToDevice")}</Text>
6262
<Switch
6363
value={isSaveDataToDevice}
6464
onValueChange={onToggleSwitch}
@@ -67,7 +67,7 @@ function InternalConfigList({ userSettings }: { userSettings: UserSetting }) {
6767
</View>
6868
<SettingButton
6969
onPress={() => testStatisticsStore.clear()}
70-
label={I18n.t("testConfig.clearHistoryStatistics")}
70+
label={AppI18n.t("testConfig.clearHistoryStatistics")}
7171
></SettingButton>
7272
</View>
7373
</View>

screens/TestRunScreen/components/TestPage.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { initialTestPageTableHeaderCols, MyTableHeaderColumn } from "../model";
1212
import { useTestRunningStatus } from "../hooks/useTestRunningStatus";
1313
import { miniStyle } from "@/theme";
1414
import { Button } from "react-native-paper";
15-
import { I18n } from "@/localize";
15+
import { AppI18n } from "@/localize";
1616
export default function TestPage({ path }: { path: string }) {
1717
const { testIpCount, setTestIpCount, getIpList } = useTestIpCount();
1818
const [testIpCoCurrentCount, setTestIpCoCurrentCount] = useState<string>("5");
@@ -93,7 +93,7 @@ export default function TestPage({ path }: { path: string }) {
9393
contentStyle={{ ...styles.paperBtnContent }}
9494
labelStyle={{ ...miniStyle.textStyle }}
9595
>
96-
{I18n.t("testRun.testRespond")}
96+
{AppI18n.t("testRun.testRespond")}
9797
</Button>
9898
<View style={{ marginRight: 5 }}></View>
9999
<Button
@@ -108,7 +108,7 @@ export default function TestPage({ path }: { path: string }) {
108108
contentStyle={{ ...styles.paperBtnContent }}
109109
labelStyle={{ ...miniStyle.textStyle }}
110110
>
111-
{I18n.t("testRun.testDownload")}
111+
{AppI18n.t("testRun.testDownload")}
112112
</Button>
113113
<View style={{ marginRight: 5 }}></View>
114114

@@ -118,18 +118,18 @@ export default function TestPage({ path }: { path: string }) {
118118
contentStyle={{ ...styles.paperBtnContent }}
119119
labelStyle={{ ...miniStyle.textStyle }}
120120
>
121-
{I18n.t("general.start")}
121+
{AppI18n.t("general.start")}
122122
</Button>
123123
</View>
124124
<View style={styles.toolbar}>
125-
<Text> {I18n.t("testRun.ipCount")}</Text>
125+
<Text> {AppI18n.t("testRun.ipCount")}</Text>
126126
<TextInput
127127
style={styles.input}
128128
onChangeText={onTestIpCountChange}
129129
value={testIpCount}
130130
keyboardType="numeric"
131131
/>
132-
<Text> {I18n.t("testRun.coCurrentCount")}</Text>
132+
<Text> {AppI18n.t("testRun.coCurrentCount")}</Text>
133133
<TextInput
134134
style={styles.input}
135135
onChangeText={(val) => setTestIpCoCurrentCount(() => val)}
@@ -138,7 +138,7 @@ export default function TestPage({ path }: { path: string }) {
138138
/>
139139
</View>
140140
<View style={styles.toolbar}>
141-
<Text>{I18n.t("testRun.testUrl")}</Text>
141+
<Text>{AppI18n.t("testRun.testUrl")}</Text>
142142
<TextInput
143143
style={{ ...styles.input, flex: 1 }}
144144
onChangeText={(val) => setTestUrl(() => val)}

screens/TestRunScreen/model.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { I18n } from '@/localize';
1+
import { AppI18n } from "@/localize";
22
import { RequestStatus } from "@/typings/index";
33
import { TableHeaderColumn } from "@/components/Table/TableHeader";
44
export type CfIpResponse = {
@@ -15,10 +15,10 @@ export type MyTableHeaderColumn = TableHeaderColumn<
1515
>;
1616

1717
export const initialTestPageTableHeaderCols: MyTableHeaderColumn[] = [
18-
{ id: "ip", label: I18n.t("general.ip"), width: 60, sort: "default" },
18+
{ id: "ip", label: AppI18n.t("general.ip"), width: 60, sort: "default" },
1919
{
2020
id: "packetLossRate",
21-
label: I18n.t("general.lossRate"),
21+
label: AppI18n.t("general.lossRate"),
2222
width: 40,
2323
sort: "default",
2424
// @ts-ignore
@@ -31,7 +31,7 @@ export const initialTestPageTableHeaderCols: MyTableHeaderColumn[] = [
3131
},
3232
{
3333
id: "respondTime",
34-
label: I18n.t("general.respondTime") + "(ms)",
34+
label: AppI18n.t("general.respondTime") + "(ms)",
3535
width: 40,
3636
sort: "default",
3737
// @ts-ignore
@@ -55,7 +55,7 @@ export const initialTestPageTableHeaderCols: MyTableHeaderColumn[] = [
5555
},
5656
{
5757
id: "downloadSpeed",
58-
label: I18n.t("general.downloadSpeed") + "(MB/s)",
58+
label: AppI18n.t("general.downloadSpeed") + "(MB/s)",
5959
width: 40,
6060
sort: "default",
6161
// @ts-ignore

screens/TestStatisticsScreen/components/StatisticsData.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { sortByIp, sortByNumber } from "@/utils/sorter";
1515
import { useState } from "react";
1616
import { Button } from "react-native-paper";
1717
import { getStoredJson, storeJson } from "@/storage/localStorage";
18-
import { I18n } from "@/localize";
18+
import { AppI18n } from "@/localize";
1919

2020
export const STORAGE_KEY_USER_SETTINGS =
2121
"STORAGE_KEY_TEST_STATISTICS_USER_CONFIG";
@@ -94,31 +94,30 @@ function StatisticsDataInternal(props: { rows: CfIpStatistics[] }) {
9494
}
9595

9696
const { sortType, columnId } = getCurrentSortConf();
97-
const [isShowAllData, setIsShowAllData] = useState<boolean>(false);
97+
const [isShowAllData, setIsShowAllData] = useState<boolean>(false);
98+
99+
const PERFORMANCE_LIMIT = 50;
98100

99-
const PERFORMANCE_LIMIT = 50;
100-
101101
// todo fix the type infer later
102102
const sortedRows = sortTableData(
103103
props.rows,
104104
columnId as `${TestStatisticsTableHeaderCol}`,
105105
sortType
106-
).slice(0, isShowAllData? props.rows.length : PERFORMANCE_LIMIT);
106+
).slice(0, isShowAllData ? props.rows.length : PERFORMANCE_LIMIT);
107107

108-
const [isShowAllHeader, setIsShowAllHeader] = useState<boolean>(false);
108+
const [isShowAllHeader, setIsShowAllHeader] = useState<boolean>(false);
109109

110110
let filteredTableHeaders = getFilteredTableHeaders(
111111
tableHeaders,
112112
isShowAllHeader
113113
);
114114

115-
getStoredJson<Record<string, any>>(
116-
STORAGE_KEY_USER_SETTINGS,
117-
{}
118-
).then(({ isShowAllHeader,isShowAllData }) => {
119-
setIsShowAllHeader(() => !!isShowAllHeader);
120-
setIsShowAllData(()=>!!isShowAllData)
121-
});
115+
getStoredJson<Record<string, any>>(STORAGE_KEY_USER_SETTINGS, {}).then(
116+
({ isShowAllHeader, isShowAllData }) => {
117+
setIsShowAllHeader(() => !!isShowAllHeader);
118+
setIsShowAllData(() => !!isShowAllData);
119+
}
120+
);
122121

123122
function onIsShowAllHeaderChange(isShowAllHeader: boolean) {
124123
setIsShowAllHeader((isShowAllHeader) => !isShowAllHeader);
@@ -128,7 +127,7 @@ function StatisticsDataInternal(props: { rows: CfIpStatistics[] }) {
128127
setIsShowAllData((isShowAllData) => !isShowAllData);
129128
storeJson(STORAGE_KEY_USER_SETTINGS, { isShowAllData });
130129
}
131-
130+
132131
return (
133132
<View style={styles.getStartedContainer}>
134133
<View
@@ -145,17 +144,17 @@ function StatisticsDataInternal(props: { rows: CfIpStatistics[] }) {
145144
onPress={() => onIsShowAllHeaderChange(!isShowAllHeader)}
146145
>
147146
{isShowAllHeader
148-
? I18n.t("testStatistics.hideSomeColumns")
149-
: I18n.t("testStatistics.showAllColumns")}
147+
? AppI18n.t("testStatistics.hideSomeColumns")
148+
: AppI18n.t("testStatistics.showAllColumns")}
150149
</Button>
151150
<Button
152151
mode="contained"
153152
contentStyle={{ marginHorizontal: -5, marginVertical: -2 }}
154153
onPress={() => onIsShowAllDataChange(!isShowAllData)}
155154
>
156155
{isShowAllData
157-
? I18n.t("general.showSortedTop") + PERFORMANCE_LIMIT
158-
: I18n.t("general.showAllData")}
156+
? AppI18n.t("general.showSortedTop") + PERFORMANCE_LIMIT
157+
: AppI18n.t("general.showAllData")}
159158
</Button>
160159
</View>
161160

screens/TestStatisticsScreen/model.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { I18n } from "@/localize";
1+
import { AppI18n } from "@/localize";
22
import { round } from "lodash-es";
33
import { TableHeaderColumn } from "@/components/Table/TableHeader";
44

@@ -16,16 +16,16 @@ export enum TestStatisticsTableHeaderCol {
1616
}
1717

1818
export const initialTestStatisticsTableHeaderCols: MyTableHeaderColumn[] = [
19-
{ id: "ip", label: I18n.t("general.ip"), width: 60, sort: "default" },
19+
{ id: "ip", label: AppI18n.t("general.ip"), width: 60, sort: "default" },
2020
{
2121
id: "totalRespondCount",
22-
label: I18n.t("testStatistics.totalRespond"),
22+
label: AppI18n.t("testStatistics.totalRespond"),
2323
width: 25,
2424
sort: "default",
2525
},
2626
{
2727
id: "respondSuccessRate",
28-
label: I18n.t("testStatistics.respondSuccessRate"),
28+
label: AppI18n.t("testStatistics.respondSuccessRate"),
2929
width: 25,
3030
sort: "default",
3131
// @ts-ignore
@@ -37,7 +37,7 @@ export const initialTestStatisticsTableHeaderCols: MyTableHeaderColumn[] = [
3737
},
3838
{
3939
id: "meanRespondTime",
40-
label: I18n.t("testStatistics.meanRespondTime") + "(s)",
40+
label: AppI18n.t("testStatistics.meanRespondTime") + "(s)",
4141
width: 25,
4242
sort: "default",
4343
// @ts-ignore
@@ -49,13 +49,13 @@ export const initialTestStatisticsTableHeaderCols: MyTableHeaderColumn[] = [
4949
},
5050
{
5151
id: "totalDownloadCount",
52-
label: I18n.t("testStatistics.totalDownload"),
52+
label: AppI18n.t("testStatistics.totalDownload"),
5353
width: 25,
5454
sort: "default",
5555
},
5656
{
5757
id: "downloadSuccessRate",
58-
label: I18n.t("testStatistics.downloadSuccessRate"),
58+
label: AppI18n.t("testStatistics.downloadSuccessRate"),
5959
width: 25,
6060
sort: "default",
6161
// @ts-ignore
@@ -67,7 +67,7 @@ export const initialTestStatisticsTableHeaderCols: MyTableHeaderColumn[] = [
6767
},
6868
{
6969
id: "meanDownloadSpeed",
70-
label: I18n.t("testStatistics.meanDownload") + "(MB/s)",
70+
label: AppI18n.t("testStatistics.meanDownload") + "(MB/s)",
7171
width: 25,
7272
sort: "default",
7373
// @ts-ignore

storage/fileAccess.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { I18n } from "@/localize";
1+
import { AppI18n } from "@/localize";
22
import { Dirs, FileSystem } from "react-native-file-access";
33
import {
44
checkMultiple,
@@ -60,7 +60,7 @@ export async function createAppFolderIfNeeded() {
6060
PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE,
6161
]);
6262
if (!hasAllPerms) {
63-
throw new Error(I18n.t("general.getPermFailed"));
63+
throw new Error(AppI18n.t("general.getPermFailed"));
6464
}
6565
try {
6666
await FileSystem.mkdir(APP_DIR);

0 commit comments

Comments
 (0)