From 6303071410e856e339d3cf379174902d245d8616 Mon Sep 17 00:00:00 2001 From: Amruth Pillai Date: Tue, 14 Nov 2023 09:14:21 +0100 Subject: [PATCH] fix(i18n): load translations from fs --- apps/client/src/components/locale-switch.tsx | 3 +-- apps/client/src/libs/lingui.ts | 11 +--------- .../dashboard/settings/_sections/profile.tsx | 9 +++++++- .../home/sections/contributors/index.tsx | 2 +- .../src/pages/home/sections/faq/index.tsx | 22 ++++++++++++++----- .../pages/home/sections/features/index.tsx | 2 +- .../home/sections/statistics/counter.tsx | 1 + .../pages/home/sections/statistics/index.tsx | 4 ++-- .../src/translation/translation.controller.ts | 4 +--- .../src/translation/translation.service.ts | 15 +++++++++++++ 10 files changed, 47 insertions(+), 26 deletions(-) diff --git a/apps/client/src/components/locale-switch.tsx b/apps/client/src/components/locale-switch.tsx index d285dbdc..d8afc324 100644 --- a/apps/client/src/components/locale-switch.tsx +++ b/apps/client/src/components/locale-switch.tsx @@ -65,8 +65,7 @@ export const LocaleSwitch = () => { i18n.locale === option.value && "opacity-100", )} /> - {option.label}{" "} - ({option.value}) + {option.label} ({option.value}) ))} diff --git a/apps/client/src/libs/lingui.ts b/apps/client/src/libs/lingui.ts index f652efa8..d57e078a 100644 --- a/apps/client/src/libs/lingui.ts +++ b/apps/client/src/libs/lingui.ts @@ -1,17 +1,8 @@ import { i18n } from "@lingui/core"; -import { axios } from "./axios"; - export const defaultLocale = "en-US"; -axios(`translation/${defaultLocale}`).then((response) => { - const messages = response.data; - i18n.loadAndActivate({ locale: defaultLocale, messages }); -}); - export async function dynamicActivate(locale: string) { - const response = await axios(`translation/${locale}`); - const messages = response.data; - + const { messages } = await import(`../locales/${locale}/messages.po`); i18n.loadAndActivate({ locale, messages }); } diff --git a/apps/client/src/pages/dashboard/settings/_sections/profile.tsx b/apps/client/src/pages/dashboard/settings/_sections/profile.tsx index 6351b185..dce3785f 100644 --- a/apps/client/src/pages/dashboard/settings/_sections/profile.tsx +++ b/apps/client/src/pages/dashboard/settings/_sections/profile.tsx @@ -99,7 +99,14 @@ export const ProfileSettings = () => { {...field} value={field.value} onValueChange={field.onChange} - options={languages.map(({ locale, name }) => ({ label: name, value: locale }))} + options={languages.map(({ locale, name }) => ({ + label: ( + <> + {name} ({locale}) + + ), + value: locale, + }))} /> diff --git a/apps/client/src/pages/home/sections/contributors/index.tsx b/apps/client/src/pages/home/sections/contributors/index.tsx index 91a8ce40..531c33fe 100644 --- a/apps/client/src/pages/home/sections/contributors/index.tsx +++ b/apps/client/src/pages/home/sections/contributors/index.tsx @@ -48,8 +48,8 @@ export const ContributorsSection = () => { key={index} viewport={{ once: true }} initial={{ opacity: 0, scale: 0 }} + className={cn(index >= 30 && "hidden lg:block")} whileInView={{ opacity: 1, scale: 1, transition: { delay: index * 0.025 } }} - className={cn(index > 30 && "hidden lg:block")} > diff --git a/apps/client/src/pages/home/sections/faq/index.tsx b/apps/client/src/pages/home/sections/faq/index.tsx index 813c1afd..49a9d000 100644 --- a/apps/client/src/pages/home/sections/faq/index.tsx +++ b/apps/client/src/pages/home/sections/faq/index.tsx @@ -9,7 +9,9 @@ import { useLanguages } from "@/client/services/resume/translation"; // Who are you, and why did you build Reactive Resume? const Question1 = () => ( - Who are you, and why did you build Reactive Resume? + + Who are you, and why did you build Reactive Resume? +

I'm Amruth Pillai, just another run-off-the-mill developer working at Elara Digital GmbH in @@ -52,7 +54,9 @@ const Question1 = () => ( // How much does it cost to run Reactive Resume? const Question2 = () => ( - How much does it cost to run Reactive Resume? + + How much does it cost to run Reactive Resume? +

It's not much honestly.{" "} @@ -95,7 +99,9 @@ const Question2 = () => ( // Other than donating, how can I support you? const Question3 = () => ( - Other than donating, how can I support you? + + Other than donating, how can I support you? +

If you speak a language other than English, sign up to be a translator on @@ -127,7 +133,9 @@ const Question4 = () => { return ( - What languages are supported on Reactive Resume? + + What languages are supported on Reactive Resume? +

Here are the languages currently supported by Reactive Resume, along with their respective @@ -180,7 +188,9 @@ const Question4 = () => { // How does the OpenAI Integration work? const Question5 = () => ( - How does the OpenAI Integration work? + + How does the OpenAI Integration work? +

OpenAI has been a game-changer for all of us. I cannot tell you how much ChatGPT has helped @@ -219,7 +229,7 @@ const Question5 = () => ( export const FAQSection = () => { return (

-
+

Frequently Asked Questions

diff --git a/apps/client/src/pages/home/sections/features/index.tsx b/apps/client/src/pages/home/sections/features/index.tsx index c506c9a2..5bec6838 100644 --- a/apps/client/src/pages/home/sections/features/index.tsx +++ b/apps/client/src/pages/home/sections/features/index.tsx @@ -112,8 +112,8 @@ export const FeaturesSection = () => { key={index} viewport={{ once: true }} initial={{ opacity: 0, x: -50 }} + className={cn(featureLabel, feature.className)} whileInView={{ opacity: 1, x: 0, transition: { delay: index * 0.1 } }} - className={cn(featureLabel, feature.className, index > 8 && "hidden lg:flex")} > {feature.icon}

{feature.title}

diff --git a/apps/client/src/pages/home/sections/statistics/counter.tsx b/apps/client/src/pages/home/sections/statistics/counter.tsx index b15f5ade..5191415a 100644 --- a/apps/client/src/pages/home/sections/statistics/counter.tsx +++ b/apps/client/src/pages/home/sections/statistics/counter.tsx @@ -25,6 +25,7 @@ export const Counter = ({ from, to }: CounterProps) => { return ( { const stats: Statistic[] = [ - { name: t`GitHub Stars`, value: 11800 }, + { name: t`GitHub Stars`, value: 12800 }, { name: t`Users Signed Up`, value: 300000 }, { name: t`Resumes Generated`, value: 400000 }, ]; @@ -19,7 +19,7 @@ export const StatisticsSection = () => {
{stats.map((stat, index) => ( -
+
{stat.name}
+ diff --git a/apps/server/src/translation/translation.controller.ts b/apps/server/src/translation/translation.controller.ts index 9f5dc0af..1eb89c34 100644 --- a/apps/server/src/translation/translation.controller.ts +++ b/apps/server/src/translation/translation.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Header, Param } from "@nestjs/common"; +import { Controller, Get, Param } from "@nestjs/common"; import { UtilsService } from "../utils/utils.service"; import { TranslationService } from "./translation.service"; @@ -20,8 +20,6 @@ export class TranslationController { } @Get("/:locale") - @Header("Content-Type", "application/octet-stream") - @Header("Content-Disposition", 'attachment; filename="messages.po"') async translation(@Param("locale") locale: string) { return this.utils.getCachedOrSet( `translation:${locale}`, diff --git a/apps/server/src/translation/translation.service.ts b/apps/server/src/translation/translation.service.ts index a0d83efb..88028482 100644 --- a/apps/server/src/translation/translation.service.ts +++ b/apps/server/src/translation/translation.service.ts @@ -31,6 +31,7 @@ export class TranslationService { } async fetchLanguages() { + const isDevelopment = this.configService.get("NODE_ENV") === "development"; const projectId = this.configService.get("CROWDIN_PROJECT_ID"); const accessToken = this.configService.get("CROWDIN_ACCESS_TOKEN"); @@ -40,6 +41,20 @@ export class TranslationService { ); const { data } = response.data as CrowdinResponse; + if (isDevelopment) { + data.push({ + data: { + language: { + id: "zu-ZA", + locale: "zu-ZA", + editorCode: "zuza", + name: "Psuedo Locale", + }, + translationProgress: 100, + }, + }); + } + return data.map(({ data }) => { return { id: data.language.id,