Localization
SVAR library provides the possibility to present interfaces of controls in different languages. It is possible to localize Calendar and controls that contain calendars: RangeCalendar, DatePicker and DateRangePicker, set time format for TimePicker and change the locale of buttons' labels in modal boxes.
Locale component
Locale: Component<{
words?: any;
optional?: boolean;
}>;
Properties:
words– a locale object that defines translations for calendar labels, button captions, and date/time formats (see the default locale below)optional– specifies how to handle keys fromwordswhen they already exist in the default locale:- false (default) – keys from
wordsoverride existing keys in the default locale - true – keys from
wordsare applied only if the key is missing in the default locale, i.e. existing translations are preserved
- false (default) – keys from
See also Handling duplicates
Using in-built locales
There are 9 locales provided:
- en-EN - American English - the default locale
- cn-CN - Chinese
- de-DE - German
- es-ES - Spanish
- fr-FR - French
- it-IT - Italian
- ja-JA - Japanese
- pt-PT - Portuguese
- ru-RU - Russian
Default locale
Locale packages are stored in a separate repository. The default locale is English, it has the following structure:
const en = {
lang: "en-US",
//calendar
calendar: {
monthFull: [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
],
monthShort: [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
],
dayFull: [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
],
dayShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
hours: "Hours",
minutes: "Minutes",
done: "Done",
clear: "Clear",
today: "Today",
am: ["am", "AM"],
pm: ["pm", "PM"],
weekStart: 7,
clockFormat: 24
},
//core
core: {
ok:"OK",
cancel:"Cancel",
select: "Select",
"No data": "No data"
},
//formats
formats: {
dateFormat: "%d.%m.%Y",
timeFormat: "%H:%i",
monthYearFormat: "%F %Y",
yearFormat: "%Y",
},
};
To use a different locale, you need to include it on a page of your application together with the Locale component, e.g. the German locale is added like this:
<script>
import { Locale } from "@svar-ui/svelte-core";
import { de } from "@svar-ui/core-locales";
</script>
Related sample: Locales
Changing locale of a control
To apply a different locale to a control, you should:
- import the control together with the Locale object:
<script>
import { Calendar, Locale } from "@svar-ui/svelte-core";
</script>
- include the necessary locale package on a page. In the example below the German locale is applied to the calendar:
<script>
import { Calendar, Locale } from "@svar-ui/svelte-core";
import { de } from "@svar-ui/core-locales";
</script>
- wrap the control you want to localize in the
<Locale>tags and use thewordsproperty to set the language:
<Locale words={de}>
<Calendar />
</Locale>

Related sample: Locales
Read more on Calendar localization.