hyperzone
hyperzone13mo ago

i18n database schema

Hi everyone! I'm working on a project where users can create items (like 'hammer' and 'screwdriver) and provide translations for these items in multiple languages (English, German, French etc). When a user selects their preferred site language, the item should be displayed in that language. I'm trying to figure out the best way to structure my Convex schema to achieve this multi-language thing. Could anyone share insights or examples on how to implement a schema that stores translations in this way? Any guidance or references to similar implementations in Convex would be really helpful!
1 Reply
ian
ian13mo ago
One idea would be to store user strings as an array with the language and value, and pass up the locale in queries, or return the translations and do the lookup there. I would use a fallback so e.g. if en_GB isn’t available it uses en_US and other languages can have defaults to English or a common regional alternative. With this you can write a few utilities to make lookup convenient. In particular I’d make a shared validator type to use in your schema or other places. Eg something like ``` const i18nString = v.array(v.object({ language: v.string(), value: v.string(), })); //… export default defineSchema({ tools: defineTable({ name: i18nString, category: i18nString, price: v.number(), }), });

Did you find this page helpful?