Next.js Discord

Discord Forum

Using .ts files for translations

Unanswered
Indian oil sardine posted this in #help-forum
Open in Discord
Indian oil sardineOP
Hi, I have recently taken to building my own lightweight solution for localization of my Next.js app.
I thought using a .ts file for translations (like "en.ts", "fr.ts", and so on..) would be a great way to do translations since intelisense would work for the translation objects.
I can see that most if not all the major localization libraries for next.js (or in general) use .json for translations.

Does using .ts for translations make sense or could it cause considerable performance?

Thank you for any input.
Have a great day!

1 Reply

Australian Terrier
[ParaglideJS](https://inlang.com/m/gerre34r/library-inlang-paraglideJs) (i18n library) maintainer here

Using .ts files for translations is perfectly fine for most projects. It will make working with translators more difficult, since they won't want to work with code, but if you aren't planning on that anyways going with .ts is a great idea.

Tip:
If you make each message it's own export, Next will be able to tree-shake the messages that aren't used in client components, making your bundle smaller.

export const message_a = "Hello"
export const message_b = "World"


you can then import the messages like so:

import * as m from "@/i18n/en.ts"
m.message_a