Skip to main content
When you need to store multilingual values in the database, you can use locale-specific columns like name, name_ko, name_en, or a locale map like name: { ko: "...", en: "..." }. Sonamu automatically selects the appropriate value for the current locale using the localizedColumn() function.

localizedColumn Function

Priority Order

localizedColumn() looks for values in the following order: When suffix columns and a locale map both exist, the suffix column for the current locale is checked first, then the locale map value. Empty strings ("") and null are skipped, and the next priority is checked.

Entity Definition

Example of an Entity with multilingual columns:

Using in Models

Processing in Subset

You can use localizedColumn in a Subsetโ€™s enhancer to deliver only a single name field to the client:

Using in API Response

Using in Frontend

The same function can be used in the frontend (exported from webโ€™s sd.generated.ts):

Supported Value Shapes

localizedColumn() supports two storage shapes: The selected value can be a string or string[]. string[] values are returned as arrays and are not stringified. For suffix columns or base columns, scalar values such as number, boolean, or bigint are stringified for backward compatibility.

Suffix Column Naming Patterns

When using suffix columns, use the {base_column}_{locale} format. When using a locale map, the base column value can store the locale-specific object.

Important Notes

  • localizedColumn is simply a function that selects column values. Query optimization (SELECTing only necessary columns) must be handled separately.
  • If all locale columns are null and the base column is also empty, undefined is returned.
  • If locale is not set in Context, defaultLocale is used.
  • If Context locale is unsupported, values are resolved from defaultLocale.

i18n Setup

Initial i18n configuration

Using the SD Function

Writing and using dictionaries