Skip to content

Conversation

@strictKraken
Copy link

#564
Apologies for the formatting, I couldn't find a contribution guide.
I wasn't sure if it's okay to use third-party libraries for translation, so I added a simple translation implementation.

I don't know Chinese very well, but AI-generated translations could be added if someone can review them.

@josdejong
Copy link
Owner

Awesome Stephan, thanks! I'll review your PR next week.

@steve02081504
Copy link

maybe add an function that allows to set i18n data?
like SetI18nData({xxx:xxx})

@strictKraken
Copy link
Author

maybe add an function that allows to set i18n data? like SetI18nData({xxx:xxx})

Great idea, i will add it

Copy link
Owner

@josdejong josdejong left a comment

Choose a reason for hiding this comment

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

First: awesome job Stephan, this is quite an undertaking. It looks solid and well taken care of. Thanks!

I made quite some inline comments. Most are small, some require some thinking though. Can you have a look at those please?

{value.length}
{value.length === 1 ? 'item' : 'items'}
</Tag>
{value.length === 1 ? t('item') : t('items')}
Copy link
Owner

Choose a reason for hiding this comment

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

I think this line should stay inside <Tag>...</Tag>, like it was?

}
}

export const russia: Language = {
Copy link
Owner

Choose a reason for hiding this comment

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

I think russia should be russian

Copy link
Owner

Choose a reason for hiding this comment

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

Can you remove this empty file i18n/types.ts?

{
type: 'button',
icon: faUndo,
title: 'Undo (Ctrl+Z)',
Copy link
Owner

Choose a reason for hiding this comment

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

Can you translate all items of the TableMenu?

text: 'Cut',
title: 'Cut selected contents, formatted with indentation (Ctrl+X)',
text: t('cut'),
title: t('cutSelectedContentFormattedWithIndentation') + ' (Ctrl+X)',
Copy link
Owner

Choose a reason for hiding this comment

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

Can you give all title translations in the createTableContextMenuItems a shorter name, like:

  • cutSelectedContentFormattedWithIndentation -> cutFormattedTitle
  • cutSelectedContentWithoutIndent-> cutCompactedTitle
  • pastClipboardContent -> pasteTitle
  • etc


if (params) {
for (const param in params) {
translation = translation.replace(new RegExp(`{{${param}}}`, 'g'), params[param])
Copy link
Owner

Choose a reason for hiding this comment

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

Can you use a replaceAll here? In case we use the same param twice.

Copy link
Author

Choose a reason for hiding this comment

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

@josdejong
replaceAll was introduced only in es2021. Currently, the lib uses es2020, and TypeScript complains about it. What's the best way to fix this behavior? Can I change compileOptions?

Copy link
Owner

Choose a reason for hiding this comment

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

O that is a good point! I think it's best to write a little replaceAll function ourselves instead of using the built-in version.

@@ -0,0 +1,42 @@
import { getContext, hasContext, setContext } from 'svelte'
Copy link
Owner

Choose a reason for hiding this comment

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

Can you run the tests and update the snapshots that are failing right now?

(this comment is not related to this piece of code)

@@ -0,0 +1,42 @@
import { getContext, hasContext, setContext } from 'svelte'
import type { Language, TranslationKey } from '$lib/types'
Copy link
Owner

Choose a reason for hiding this comment

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

Can you write documentation in the README.md about the new language feature?

(this comment is not related to this piece of code)


export function t(key: keyof TranslationKey, params?: Record<string, string>): string {
const ctx = getI18nContext()
let translation: string = get(ctx.values)?.[key] ?? key
Copy link
Owner

Choose a reason for hiding this comment

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

I think it would be good to add an extra fallback to the default language, English. When we add new language keys for new features, I think it can easily happen that languages are a step behind, so it may be good to cater for that.

So then it can become:

let translation: string = get(ctx.values)?.[key] ?? defaultLanguage?.[key] ?? key

What do you think?

}

export function getI18nContext() {
return getContext<I18nContext>(I18N_CONTEXT_KEY)
Copy link
Owner

Choose a reason for hiding this comment

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

When running in a develop environment, I get errors like:

Uncaught Svelte error: lifecycle_outside_component `getContext(...)` can only be used during component initialisation

Did you encounter that too?

@josdejong
Copy link
Owner

@strictKraken did you see my feedback from last week?

@strictKraken
Copy link
Author

strictKraken commented Nov 19, 2025

@strictKraken did you see my feedback from last week?

@josdejong

Thanks for the detailed review! I was a bit busy last week, so I'll take a closer look at the review and make some fixes this week !!

@josdejong
Copy link
Owner

Thanks! No problem at all, no need to rush or anything.

@fevrax
Copy link

fevrax commented Nov 23, 2025

This PR is excellent, keep it up.

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.

4 participants