Skip to content
Hekana Spray
Documentation
Getting started
Theme development
Components and tags

Localization

Apps and custom code

Examples and recipes
API reference
Publishing
Build apps
AI development

Localized section

How a Sneferu section shows English and Arabic: the two locale files, the t() calls and localized settings, from the starter theme hero.

On this page

What you'll build

The same hero in English and Arabic from two language files, with the layout flipping to right to left. The Result below is drawn by the real Sneferu renderer from the code on this page.

Result

Requirements

  • Node.js 20 or newer
  • A theme made with npx sneferu init. Every file below is part of it.
  • The preview running: npx sneferu dev

Code

Concepts this teaches: Locale files, t(), Localized settings, Right to left.

These files come from the starter theme that npx sneferu init creates. The example is locales/en.json.

locales/en.jsonJSON
{
  "skip_to_content": "Skip to content",
  "menu": "Menu",
  "search": "Search",
  "search_placeholder": "What are you looking for?",
  "home": "Home",
  "breadcrumb": "Breadcrumb",
  "sale": "Sale",
  "sold_out_badge": "Sold out",
  "products_label": "products",
  "sort_by": "Sort by",
  "filters": "Filters",
  "results_for": "Results for",
  "results_label": "results",
  "newsletter_cta": "Subscribe",
  "payment_methods": "Payment methods",
  "product_info": "Product details",
  "hero_title": "Everything you need, in one place",
  "hero_text": "Pick what you like and check out in a minute.",
  "product_note": "Order confirmation and delivery details are sent by email after you pay."
}
locales/ar.jsonJSON
{
  "skip_to_content": "تخطي إلى المحتوى",
  "menu": "القائمة",
  "search": "بحث",
  "search_placeholder": "بتدور على إيه؟",
  "home": "الرئيسية",
  "breadcrumb": "مسار الصفحة",
  "sale": "خصم",
  "sold_out_badge": "نفد المخزون",
  "products_label": "منتج",
  "sort_by": "ترتيب حسب",
  "filters": "فلاتر",
  "results_for": "نتائج البحث عن",
  "results_label": "نتيجة",
  "newsletter_cta": "اشترك",
  "payment_methods": "طرق الدفع",
  "product_info": "تفاصيل المنتج",
  "hero_title": "كل اللي محتاجه في مكان واحد",
  "hero_text": "اختار اللي يعجبك وكمّل الطلب في دقيقة.",
  "product_note": "هيوصلك تأكيد الطلب وتفاصيل التسليم على الإيميل بعد الدفع."
}

Download: locales/en.json, locales/ar.json in the public SDK repo at commit c96cbf2, or the whole starter theme folder.

Preview

Result

Customize

Settings in the hk-schema of sections/hero.snf. The merchant changes them in the theme editor; the default is what a new section starts with.

SettingLabelTypeDefaultNotes
titleHeadingtextset per language
subtitleTexttextareaset per language
button_labelButtontext{"ar":"تسوق دلوقتي","en":"Shop now"}set per language
button_linkButton linklink/products
button_styleButton styleselectsolidone of solid, outline, ghost
imageImageimage
image_altImage descriptiontextset per language
alignText alignmentselectstartone of start, center
backgroundBackgroundcolortheme:secondary
text_colorText colourcolortheme:background
padding_yVertical paddingrange880 to 200 in steps of 8

Text keys the code reads with t(). Change the English text in locales/en.json and the Arabic text under the same key in locales/ar.json.

KeyEnglish text
hero_titleEverything you need, in one place
hero_textPick what you like and check out in a minute.

How it works

  • This code uses the tags .
  • locales/en.json and locales/ar.json hold the same keys; each value is the text for that language.
  • The hero prints t('hero_title') and t('hero_text'), which look the key up in the visitor's language (see Lookups).
  • A setting marked localized: true in the schema is stored once per language, so the merchant types the Arabic and English text separately.
  • default: t('hero_title') makes the language file the fallback when the setting is empty (see Filters).
  • Arabic pages are laid out right to left automatically; your CSS does not need a second set of rules.

Next steps