Skip to content

Support for language translations and date formats #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 154 commits into
base: import-splitwise
Choose a base branch
from

Conversation

Rosso2004
Copy link

@Rosso2004 Rosso2004 commented Mar 20, 2025

Description
This PR adds multilingual support using i18n. Now, new languages can be added simply by creating a new folder inside /public/locales, named with the language code (e.g., en, es, de, it, etc.).
For example, to add German, just duplicate the en folder (or any other existing language folder) and translate the JSON files inside it. No code modifications are required to enable a new language.

Main Changes
Added i18n support with JSON-based language management.
Translation structure located in /public/locales/{lang_code}/.

New Environment Variables (.env)

#********* DATE FORMAT *********  
DATE_FORMAT_VARIANT_1="dd-MM-yyyy"  
DATE_FORMAT_VARIANT_2="dd MMM yyyy"  
DATE_FORMAT_VARIANT_3="dd MMM"  
DATE_FORMAT_VARIANT_4="dd MMM"  
DATE_FORMAT_VARIANT_5="dd MMM, yyyy"  

Preview
image
image

KMKoushik and others added 17 commits November 9, 2024 07:09
* add edit expense

* add edit expense changes

* fix build

* fix edit not working on exact match

* set share to zero

* fix deleting user on edit not working

* fix auto load to expense page

* make split share nice
* Add authentik provider

* Add authentik provider

* Add authentik provider

* Add authentik provider
* Add nextauth_internal_url

* Add NEXTAUTH_URL_INTERNAL option

---------

Co-authored-by: KM Koushik <koushikmohan1996@gmail.com>
* feat: add invite-only flag

* feat: wrap adapter to enforce invite-only mode
this updates the invite email sending function to prevent sending
an invite email if the environment flag is not set.  this matches
the behavior with the frontend and prevents malicious actors from
bypassing the logic

fixes oss-apps#174
Gestione della lingua nella pagina "Account" e traduzione della pagina "Account"
@Rosso2004 Rosso2004 mentioned this pull request Mar 22, 2025

// Funzione per ottenere il nome della lingua dal file di traduzione
const getLanguageName = (languageCode: string): string => {
return t(`ui/change_language_details/languages/${languageCode}`) || languageCode;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not that familiar with i18next, but did you look into a type safe implementation?
https://www.i18next.com/overview/typescript

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I have not tried a type-safe implementation, if you could do it that would be better, I have never experimented with it and I would not know how to move

@Rosso2004 Rosso2004 requested a review from krokosik April 18, 2025 22:52
@krokosik
Copy link
Collaborator

@Rosso2004 The PR is awesome and I would love to have it in Split Pro, but I would wait until there are more collaborators added to the project that would actually allow us to merge this. And I could take a swing at making this type safe once that happens


// Restores the language selected when opening the drawer
const handleClose = () => {
setSelectedLanguage(initialLanguage); // Ripristina la lingua iniziale
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still italian comments left :/

// Update the initial language when the drawer is opened
useEffect(() => {
if (languageOpen) {
setInitialLanguage(i18n.language); // Set the initial language
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that comments like setInitialLanguage is for setting the initial language is a bit overkill. Some of the comments are unnecessay and the code is self explaining enough without the need for extra clutter

Comment on lines 129 to 142
<SplitEqualSection t={t} />
</TabsContent>
<TabsContent value={SplitType.PERCENTAGE}>
<SplitByPercentageSection />
<SplitByPercentageSection t={t} />
</TabsContent>
<TabsContent value={SplitType.EXACT}>
<SplitByAmountSection />
<SplitByAmountSection t={t}/>
</TabsContent>
<TabsContent value={SplitType.SHARE}>
<SplitByShareSection />
<SplitByShareSection t={t} />
</TabsContent>
<TabsContent value={SplitType.ADJUSTMENT}>
<SplitByAdjustmentSection />
<SplitByAdjustmentSection t={t} />
</TabsContent>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the value need to be passed as a prop? Shouldn't the components be able to get the translation object themselves?

Comment on lines +9 to +10
import {useTranslation} from "react-i18next";
import {type TFunction} from "i18next";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run Prettier to maintain consistent formatting. The imports should look like the ones above with spaces near curly brackets

@@ -35,7 +37,8 @@ export const UploadFile: React.FC = () => {
if (!file) return;

if (file.size > FILE_SIZE_LIMIT) {
toast.error(`File should be less than ${FILE_SIZE_LIMIT / 1024 / 1024}MB`);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this newline

)}
</div>
<p className="text-xs text-gray-500">
{format(e.expense.expenseDate, 'dd MMM')}
{format(e.expense.expenseDate, process.env.NEXT_PUBLIC_DATE_FORMAT_VARIANT_3 ?? 'dd MMM')}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use env object

@@ -147,7 +151,8 @@ const FriendBalance: React.FC<{
currency: string;
id: number;
hasMore?: boolean;
}> = ({ friend, amount, isPositive, currency, id, hasMore }) => {
t: TFunction<string, undefined>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any use of this prop drilling? You can just call the hook again here

@@ -12,18 +12,20 @@ import { GroupAvatar } from '~/components/ui/avatar';
import { toUIString } from '~/utils/numbers';
import { motion } from 'framer-motion';
import { type NextPageWithUser } from '~/types';
import {useTranslation} from "react-i18next";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

@@ -69,4 +75,4 @@ FEEDBACK_EMAIL=

# Discord webhook for error notifications
DISCORD_WEBHOOK_URL=
#********* END OF OPTIONAL ENV VARS *********
#********* END OF OPTIONAL ENV VARS *********
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

@@ -30,4 +30,4 @@ services:

volumes:
database:
minio:
minio:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

@Rosso2004 Rosso2004 changed the base branch from main to import-splitwise May 21, 2025 21:13
@krokosik
Copy link
Collaborator

@Rosso2004 I have been added as a Collaborator so we can proceed with the review and merging the changes :)

@Rosso2004
Copy link
Author

Thank you so much

@krokosik krokosik added this to the 1.4 milestone May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.