[v0.5.0] — 2026-11-28
Breaking changes
The store callback
queryable?/0is nowLocalize.Translate.Store.queryable?/1and takes the schema, so a store shared by schemas kept in different data layers can answer for each. A custom store changesdef queryable?todef queryable?(_schema).Localize.Translate.QueryBuilderchecksLocalize.Translate.Store.queryable?/1and raises anArgumentErrorwhen a query on a schema whose store is not queryable is compiled, such as one usingSiblingResource. Such a query already failed in the database, against its virtual container.
Added
Localize.Translate.Store.fetch_translation/4may return{:error, exception}for a store that could not answer, kept apart from:errorfor a missing translation.translate/2,3stop the fallback chain and return the base value;translate!/3raises the exception.
Changed
- A locale's translations are stored and read under the CLDR locale it names, whatever locales Localize is configured for: with only
enandfrconfigured,heis:heandpt-BRis:pt, where both were:en. Chains come fromLocalize.Locale.fallback_chain/2; requireslocalize ~> 1.11.
[v0.4.0] — 2026-11-24
Upgrading from an earlier release? See Migrating to 0.4, which covers the change from the translate_field database function to plain SQL and the database housekeeping.
Added
:default_localealso takes a{module, function, arguments}tuple, called with the struct (ornilfor a query), for a default known only at runtime.default_locale/1resolves it, andQueryBuilder.translated/4andtranslated_as/4take a:default_localeoption.validate_translations/1is a changeset validation that refuses translations for the record's own default locale, resolving a function default from the changed record, and, for a map container, invalid or unlisted locales.reflection/1generates the__trans__/1reflection with defaults for every key, for code that builds a translatable module withoutuse Localize.Translate, such as an Ash extension.locale_id/1validates a locale and returns the CLDR locale id translations are keyed by, or an error, for code that stores or reads translations itself.locale_chain/2expands a locale or list into the CLDR fallback chain the reads walk, leaving out invalid locales, with:supportedand:default_localeoptions, for code that builds its own lookups such as a data-layer calculation.__trans__(:associations)names the fields holding related records thattranslate/2also translates: an Ecto schema's associations and embeds by default, or a list of its own from a module that defines__trans__/1itself.
Changed
translate/2,3filter the locale chain by the schema's:locales, keeping the default locale, as queries do, so a stored locale the schema no longer lists is not read;translate/2filters each related record by its own:locales.translate/3returns the base value for a field that is not translatable, andnilfor a field the struct lacks or a value that is not a struct, where it raised;translate!/3raises anArgumentErrorfor these instead of aRuntimeError. Both take a string field name without creating an atom.A
niltranslation counts as missing intranslate/2,3, so a chain moves on to its next locale where it stopped at the base value, andtranslate!/3raises for it. Queries apply the same rule, including anilbase value at the default locale.QueryBuilderno longer needs thetranslate_fielddatabase function: every query reads the locale chain in plain SQL, the first four locales as directjsonbexpressions, so aLanguageTagquery runs as fast as a hand-written one and about twenty-five times faster than the function. New applications skipmix localize.translate.gen.translate_function.
Deprecated
mix localize.translate.gen.translate_functionwarns when run and will be removed in a future release, since queries no longer call thetranslate_fieldfunction it creates.
Fixed
A query on a schema whose default locale is not in
:localesdropped the default from the chain, so it read a later translation instead of the base column; the default locale is now kept.A language CLDR has no data for, such as
"tlh", resolves to the rootundand is now left out of a chain and refused in:locales; every such language was read under the one"und"key.translate!/3loads translations before resolving, astranslate/3does, so it works withStore.SiblingResource; it raised "translation doesn't exist" for every locale.translate/1,2return a value that is not a struct unchanged, where they raisedFunctionClauseError.Store.SiblingResource.load_translations/2checks its options and the subject's key before querying and returns{:error, %ArgumentError{}}for each problem, instead of raising and rescuing; only the repo call is rescued, returning the database error.translatable?/2no longer creates an atom from a string field name, and returnsfalseinstead of raising for a module that does not useLocalize.Translateor for arguments that are not a module and a field name.Store.Embeddedno longer raises on a container or locale entry that is not a map, which ajsonbcolumn can hold: reads are a miss andput_translation/5returns{:error, %ArgumentError{}}. A write of an unknown locale or field to a struct container is refused instead of adding a stray key.A runtime-locale query works with any binding name and on joined schemas; it guessed the table alias from the binding name, so
from b in Book(aliasa0) failed. A literal locale is now expanded and validated as a runtime one is, so:"es-419"reads:es.QueryBuilder.translated/3with a literal chain such as[:it, :es]returned the base column when the first locale had no translation; it now moves on, as a runtime chain andtranslate/3do.A runtime-locale query on a schema with no
:default_localeno longer treats:enas the default.translate/2no longer raises on a struct that is not an Ecto schema, or on a related value that is a plain map; it translates only related values that are themselves translatable structs.translate/2,3andQueryBuilder.translated/3no longer raise on an invalid locale,nilincluded: it is left out of the fallback chain, so the base value is returned.translate!/3still raisesLocalize.InvalidLocaleError.
[v0.3.0] — 2026-11-24
Added
translations/3takesfields_module:, a per-locale embedded schema of your own used in place of the generatedFields, so state such as a translator or an update time can be kept beside each locale's translations. It must define every translatable field as a:string, which is checked when the parent schema compiles.
Changed
translations/3raises anArgumentErrorat compile time for an option it does not know, where it ignored it.
Fixed
Localize.Translate.JSONencodesDate,Time,NaiveDateTimeandDateTimeas ISO 8601 strings and aDecimalas its text, so an embedded schema with such a field can be stored. It raised on them.
[v0.2.0] — 2026-08-01
The store behaviour is new public API and its first consumer — the Ash integration — has not yet written an adapter against it. The package stays on a 0.x line until that shape is agreed, so it can change without a major bump.
Added
Localize.Translate.Store— a behaviour for translation storage, so translations need not live on the subject. It is subject-and-field shaped: a store receives the whole subject rather than an extracted key, so a CLDR fallback chain resolves in one pass.Localize.Translate.Store.Embedded— the default store, implementing the container-map storage this library has always used. Existing schemas keep working unchanged.Localize.Translate.Store.SiblingResource— a store keeping translations in a sibling table, one row per(subject, locale). For per-translation workflow state, per-locale permissions, row-level translation history, or concurrent editing across locales.A schema selects its store with
use Localize.Translate, store: MyStoreorstore: {MyStore, options}.
Changed
Requires
localize ~> 1.0. The previous requirement of~> 0.32excluded it.Test database connection settings read the standard
PG*environment variables, so the same configuration works on CI and on a developer machine.
Fixed
Mix.Tasks.Localize.Translate.Gen.TranslateFunction.format_string!/1returns a binary rather than iodata, and no longer carries a@dialyzer {:no_return, ...}annotation that claimed it never returns.
[v0.1.0] — 2026-05-13
Initial release. Provides embedded translations for Ecto.Schema modules — use Localize.Translate declares translatable fields, locales, and default locale; Localize.Translate.translate/2,3 reads translations at runtime, and Localize.Translate.QueryBuilder.translated/3 builds matching Ecto.Query fragments.
Built on :localize — atoms, strings, and %Localize.LanguageTag{} are accepted as locales in :locales, in translate/N, and in QueryBuilder.translated/3, all validated and normalised via Localize.validate_locale/1; fallback chains walk CLDR parent locales (filtered to the schema's supported locales for query building) and translate/1,2 default to Localize.get_locale/0.