Skip to content

Commit

Permalink
refactor: rename I18N
Browse files Browse the repository at this point in the history
  • Loading branch information
xianshenglu committed May 27, 2022
1 parent d17bc18 commit 056f6f4
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 48 deletions.
2 changes: 1 addition & 1 deletion localize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ I18n.translations = {
en,
};

export { I18n };
export { I18n as AppI18n };
8 changes: 4 additions & 4 deletions navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from "../types";
import LinkingConfiguration from "./LinkingConfiguration";
import TestStatisticsScreen from "@/screens/TestStatisticsScreen";
import { I18n } from "@/localize";
import { AppI18n } from "@/localize";

export default function Navigation({
colorScheme,
Expand Down Expand Up @@ -86,7 +86,7 @@ function BottomTabNavigator() {
name="TestRun"
component={TestRunScreen}
options={({ navigation }: RootTabScreenProps<"TestRun">) => ({
title: I18n.t("testRun.title"),
title: AppI18n.t("testRun.title"),
tabBarIcon: ({ color }) => <TabBarIcon name="code" color={color} />,
headerRight: () => (
<Pressable
Expand All @@ -109,7 +109,7 @@ function BottomTabNavigator() {
name="TestStatistics"
component={TestStatisticsScreen}
options={({ navigation }: RootTabScreenProps<"TestStatistics">) => ({
title: I18n.t("testStatistics.title"),
title: AppI18n.t("testStatistics.title"),
tabBarIcon: ({ color }) => <TabBarIcon name="code" color={color} />,
headerRight: () => (
<Pressable
Expand All @@ -132,7 +132,7 @@ function BottomTabNavigator() {
name="TestConfig"
component={TestConfigScreen}
options={{
title: I18n.t("testConfig.title"),
title: AppI18n.t("testConfig.title"),
tabBarIcon: ({ color }) => <TabBarIcon name="code" color={color} />,
}}
/>
Expand Down
6 changes: 3 additions & 3 deletions screens/TestConfigScreen/components/ConfigList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createAppFolderIfNeeded, initDefaultFilesIfNeeded } from "@/storage/fil
import { userSettingsStore, UserSetting } from "@/store/UserSettings";
import { observer } from "mobx-react";
import { testStatisticsStore } from "@/store/TestStatistics";
import { I18n } from "@/localize";
import { AppI18n } from "@/localize";
import { useTheme } from "@react-navigation/native";

export const ConfigList = observer(() => (
Expand Down Expand Up @@ -58,7 +58,7 @@ function InternalConfigList({ userSettings }: { userSettings: UserSetting }) {
<View style={styles.container}>
<View style={styles.list}>
<View style={styles.item}>
<Text>{I18n.t("testConfig.saveAllDataToDevice")}</Text>
<Text>{AppI18n.t("testConfig.saveAllDataToDevice")}</Text>
<Switch
value={isSaveDataToDevice}
onValueChange={onToggleSwitch}
Expand All @@ -67,7 +67,7 @@ function InternalConfigList({ userSettings }: { userSettings: UserSetting }) {
</View>
<SettingButton
onPress={() => testStatisticsStore.clear()}
label={I18n.t("testConfig.clearHistoryStatistics")}
label={AppI18n.t("testConfig.clearHistoryStatistics")}
></SettingButton>
</View>
</View>
Expand Down
14 changes: 7 additions & 7 deletions screens/TestRunScreen/components/TestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { initialTestPageTableHeaderCols, MyTableHeaderColumn } from "../model";
import { useTestRunningStatus } from "../hooks/useTestRunningStatus";
import { miniStyle } from "@/theme";
import { Button } from "react-native-paper";
import { I18n } from "@/localize";
import { AppI18n } from "@/localize";
export default function TestPage({ path }: { path: string }) {
const { testIpCount, setTestIpCount, getIpList } = useTestIpCount();
const [testIpCoCurrentCount, setTestIpCoCurrentCount] = useState<string>("5");
Expand Down Expand Up @@ -93,7 +93,7 @@ export default function TestPage({ path }: { path: string }) {
contentStyle={{ ...styles.paperBtnContent }}
labelStyle={{ ...miniStyle.textStyle }}
>
{I18n.t("testRun.testRespond")}
{AppI18n.t("testRun.testRespond")}
</Button>
<View style={{ marginRight: 5 }}></View>
<Button
Expand All @@ -108,7 +108,7 @@ export default function TestPage({ path }: { path: string }) {
contentStyle={{ ...styles.paperBtnContent }}
labelStyle={{ ...miniStyle.textStyle }}
>
{I18n.t("testRun.testDownload")}
{AppI18n.t("testRun.testDownload")}
</Button>
<View style={{ marginRight: 5 }}></View>

Expand All @@ -118,18 +118,18 @@ export default function TestPage({ path }: { path: string }) {
contentStyle={{ ...styles.paperBtnContent }}
labelStyle={{ ...miniStyle.textStyle }}
>
{I18n.t("general.start")}
{AppI18n.t("general.start")}
</Button>
</View>
<View style={styles.toolbar}>
<Text> {I18n.t("testRun.ipCount")}</Text>
<Text> {AppI18n.t("testRun.ipCount")}</Text>
<TextInput
style={styles.input}
onChangeText={onTestIpCountChange}
value={testIpCount}
keyboardType="numeric"
/>
<Text> {I18n.t("testRun.coCurrentCount")}</Text>
<Text> {AppI18n.t("testRun.coCurrentCount")}</Text>
<TextInput
style={styles.input}
onChangeText={(val) => setTestIpCoCurrentCount(() => val)}
Expand All @@ -138,7 +138,7 @@ export default function TestPage({ path }: { path: string }) {
/>
</View>
<View style={styles.toolbar}>
<Text>{I18n.t("testRun.testUrl")}</Text>
<Text>{AppI18n.t("testRun.testUrl")}</Text>
<TextInput
style={{ ...styles.input, flex: 1 }}
onChangeText={(val) => setTestUrl(() => val)}
Expand Down
10 changes: 5 additions & 5 deletions screens/TestRunScreen/model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { I18n } from '@/localize';
import { AppI18n } from "@/localize";
import { RequestStatus } from "@/typings/index";
import { TableHeaderColumn } from "@/components/Table/TableHeader";
export type CfIpResponse = {
Expand All @@ -15,10 +15,10 @@ export type MyTableHeaderColumn = TableHeaderColumn<
>;

export const initialTestPageTableHeaderCols: MyTableHeaderColumn[] = [
{ id: "ip", label: I18n.t("general.ip"), width: 60, sort: "default" },
{ id: "ip", label: AppI18n.t("general.ip"), width: 60, sort: "default" },
{
id: "packetLossRate",
label: I18n.t("general.lossRate"),
label: AppI18n.t("general.lossRate"),
width: 40,
sort: "default",
// @ts-ignore
Expand All @@ -31,7 +31,7 @@ export const initialTestPageTableHeaderCols: MyTableHeaderColumn[] = [
},
{
id: "respondTime",
label: I18n.t("general.respondTime") + "(ms)",
label: AppI18n.t("general.respondTime") + "(ms)",
width: 40,
sort: "default",
// @ts-ignore
Expand All @@ -55,7 +55,7 @@ export const initialTestPageTableHeaderCols: MyTableHeaderColumn[] = [
},
{
id: "downloadSpeed",
label: I18n.t("general.downloadSpeed") + "(MB/s)",
label: AppI18n.t("general.downloadSpeed") + "(MB/s)",
width: 40,
sort: "default",
// @ts-ignore
Expand Down
35 changes: 17 additions & 18 deletions screens/TestStatisticsScreen/components/StatisticsData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { sortByIp, sortByNumber } from "@/utils/sorter";
import { useState } from "react";
import { Button } from "react-native-paper";
import { getStoredJson, storeJson } from "@/storage/localStorage";
import { I18n } from "@/localize";
import { AppI18n } from "@/localize";

export const STORAGE_KEY_USER_SETTINGS =
"STORAGE_KEY_TEST_STATISTICS_USER_CONFIG";
Expand Down Expand Up @@ -94,31 +94,30 @@ function StatisticsDataInternal(props: { rows: CfIpStatistics[] }) {
}

const { sortType, columnId } = getCurrentSortConf();
const [isShowAllData, setIsShowAllData] = useState<boolean>(false);
const [isShowAllData, setIsShowAllData] = useState<boolean>(false);

const PERFORMANCE_LIMIT = 50;

const PERFORMANCE_LIMIT = 50;

// todo fix the type infer later
const sortedRows = sortTableData(
props.rows,
columnId as `${TestStatisticsTableHeaderCol}`,
sortType
).slice(0, isShowAllData? props.rows.length : PERFORMANCE_LIMIT);
).slice(0, isShowAllData ? props.rows.length : PERFORMANCE_LIMIT);

const [isShowAllHeader, setIsShowAllHeader] = useState<boolean>(false);
const [isShowAllHeader, setIsShowAllHeader] = useState<boolean>(false);

let filteredTableHeaders = getFilteredTableHeaders(
tableHeaders,
isShowAllHeader
);

getStoredJson<Record<string, any>>(
STORAGE_KEY_USER_SETTINGS,
{}
).then(({ isShowAllHeader,isShowAllData }) => {
setIsShowAllHeader(() => !!isShowAllHeader);
setIsShowAllData(()=>!!isShowAllData)
});
getStoredJson<Record<string, any>>(STORAGE_KEY_USER_SETTINGS, {}).then(
({ isShowAllHeader, isShowAllData }) => {
setIsShowAllHeader(() => !!isShowAllHeader);
setIsShowAllData(() => !!isShowAllData);
}
);

function onIsShowAllHeaderChange(isShowAllHeader: boolean) {
setIsShowAllHeader((isShowAllHeader) => !isShowAllHeader);
Expand All @@ -128,7 +127,7 @@ function StatisticsDataInternal(props: { rows: CfIpStatistics[] }) {
setIsShowAllData((isShowAllData) => !isShowAllData);
storeJson(STORAGE_KEY_USER_SETTINGS, { isShowAllData });
}

return (
<View style={styles.getStartedContainer}>
<View
Expand All @@ -145,17 +144,17 @@ function StatisticsDataInternal(props: { rows: CfIpStatistics[] }) {
onPress={() => onIsShowAllHeaderChange(!isShowAllHeader)}
>
{isShowAllHeader
? I18n.t("testStatistics.hideSomeColumns")
: I18n.t("testStatistics.showAllColumns")}
? AppI18n.t("testStatistics.hideSomeColumns")
: AppI18n.t("testStatistics.showAllColumns")}
</Button>
<Button
mode="contained"
contentStyle={{ marginHorizontal: -5, marginVertical: -2 }}
onPress={() => onIsShowAllDataChange(!isShowAllData)}
>
{isShowAllData
? I18n.t("general.showSortedTop") + PERFORMANCE_LIMIT
: I18n.t("general.showAllData")}
? AppI18n.t("general.showSortedTop") + PERFORMANCE_LIMIT
: AppI18n.t("general.showAllData")}
</Button>
</View>

Expand Down
16 changes: 8 additions & 8 deletions screens/TestStatisticsScreen/model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { I18n } from "@/localize";
import { AppI18n } from "@/localize";
import { round } from "lodash-es";
import { TableHeaderColumn } from "@/components/Table/TableHeader";

Expand All @@ -16,16 +16,16 @@ export enum TestStatisticsTableHeaderCol {
}

export const initialTestStatisticsTableHeaderCols: MyTableHeaderColumn[] = [
{ id: "ip", label: I18n.t("general.ip"), width: 60, sort: "default" },
{ id: "ip", label: AppI18n.t("general.ip"), width: 60, sort: "default" },
{
id: "totalRespondCount",
label: I18n.t("testStatistics.totalRespond"),
label: AppI18n.t("testStatistics.totalRespond"),
width: 25,
sort: "default",
},
{
id: "respondSuccessRate",
label: I18n.t("testStatistics.respondSuccessRate"),
label: AppI18n.t("testStatistics.respondSuccessRate"),
width: 25,
sort: "default",
// @ts-ignore
Expand All @@ -37,7 +37,7 @@ export const initialTestStatisticsTableHeaderCols: MyTableHeaderColumn[] = [
},
{
id: "meanRespondTime",
label: I18n.t("testStatistics.meanRespondTime") + "(s)",
label: AppI18n.t("testStatistics.meanRespondTime") + "(s)",
width: 25,
sort: "default",
// @ts-ignore
Expand All @@ -49,13 +49,13 @@ export const initialTestStatisticsTableHeaderCols: MyTableHeaderColumn[] = [
},
{
id: "totalDownloadCount",
label: I18n.t("testStatistics.totalDownload"),
label: AppI18n.t("testStatistics.totalDownload"),
width: 25,
sort: "default",
},
{
id: "downloadSuccessRate",
label: I18n.t("testStatistics.downloadSuccessRate"),
label: AppI18n.t("testStatistics.downloadSuccessRate"),
width: 25,
sort: "default",
// @ts-ignore
Expand All @@ -67,7 +67,7 @@ export const initialTestStatisticsTableHeaderCols: MyTableHeaderColumn[] = [
},
{
id: "meanDownloadSpeed",
label: I18n.t("testStatistics.meanDownload") + "(MB/s)",
label: AppI18n.t("testStatistics.meanDownload") + "(MB/s)",
width: 25,
sort: "default",
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions storage/fileAccess.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { I18n } from "@/localize";
import { AppI18n } from "@/localize";
import { Dirs, FileSystem } from "react-native-file-access";
import {
checkMultiple,
Expand Down Expand Up @@ -60,7 +60,7 @@ export async function createAppFolderIfNeeded() {
PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE,
]);
if (!hasAllPerms) {
throw new Error(I18n.t("general.getPermFailed"));
throw new Error(AppI18n.t("general.getPermFailed"));
}
try {
await FileSystem.mkdir(APP_DIR);
Expand Down

0 comments on commit 056f6f4

Please sign in to comment.