Added support for the homepage languages

This commit is contained in:
Joao Ramos
2024-02-29 18:26:41 +00:00
parent 773480875f
commit 79e51d6294
2 changed files with 8 additions and 3 deletions

View File

@@ -23,7 +23,7 @@ interface Contact {
number: string; number: string;
} }
async function get(req: NextApiRequest, res: NextApiResponse) { async function get(req: NextApiRequest, res: NextApiResponse) {
const { code } = req.query as { code: string }; const { code, language = 'en' } = req.query as { code: string, language: string};
const usersQuery = query( const usersQuery = query(
collection(db, "users"), collection(db, "users"),
@@ -44,8 +44,10 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
}) as Contact[]; }) as Contact[];
const country = countryCodes.findOne("countryCode" as any, code); const country = countryCodes.findOne("countryCode" as any, code);
const key = language === 'ar' ? 'countryNameLocal' : 'countryNameEn';
res.json({ res.json({
label: country.countryNameEn, label: country[key],
entries, entries,
}); });
} }

View File

@@ -23,6 +23,8 @@ interface Contact {
number: string; number: string;
} }
async function get(req: NextApiRequest, res: NextApiResponse) { async function get(req: NextApiRequest, res: NextApiResponse) {
const { language = 'en' } = req.query as { language: string };
const usersQuery = query( const usersQuery = query(
collection(db, "users"), collection(db, "users"),
where("type", "==", "agent") where("type", "==", "agent")
@@ -50,8 +52,9 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
const result = Object.keys(data).map((code) => { const result = Object.keys(data).map((code) => {
const country = countryCodes.findOne("countryCode" as any, code); const country = countryCodes.findOne("countryCode" as any, code);
const key = language === 'ar' ? 'countryNameLocal' : 'countryNameEn';
return { return {
label: country.countryNameEn, label: country[key],
key: code, key: code,
entries: data[code], entries: data[code],
}; };