API / Apache FreeMarker Interview questions
How do you internationalize FreeMarker templates for different locales?
FreeMarker's formatting built-ins are locale-aware automatically once a Locale is set on the Configuration, request-specific settings, or passed to getTemplate(name, locale): number formatting (?string), date/time formatting, and comparison all follow that locale without any extra template code.
Beyond formatting individual values, the localized_lookup setting lets an entire template be swapped per locale, not just the strings inside it: requesting "home.ftl" with a Locale of de_DE causes FreeMarker to look for home_de_DE.ftl, then home_de.ftl, then fall back to the base home.ftl if no more specific variant exists. This is useful when a locale needs a genuinely different layout, not just translated text.
For translated text itself, the common pattern is to expose a message-lookup object (often backed by a Java ResourceBundle) in the data model, so templates call something like ${msg("welcome.title")} rather than hardcoding language-specific strings directly in the FTL.
More Related questions...