@@ -22,18 +22,25 @@ const imageBackground = true
2222// Set to true and run the script once to update the image manually.
2323const forceImageUpdate = false
2424
25- // Set locale and locale strings
25+ // Set the two-letter locale code for the date and weather formatting.
2626const locale = "en"
2727
28- const localeString = {
28+ // You can change the language or wording of any other text in the widget.
29+ const localizedText = {
2930
30- "goodnightStr" : function ( ) { return "Good night." } ,
31- "goodmorningStr" : function ( ) { return "Good morning." } ,
32- "goodafternoonStr" : function ( ) { return "Good afternoon." } ,
33- "goodeveningStr" : function ( ) { return "Good evening." } ,
34- "nexthourStr" : function ( ) { return "Next hour" } ,
35- "tomorrowStr" : function ( ) { return "Tomorrow" } ,
36- "noEventMessage" : function ( ) { return "Enjoy the rest of your day." }
31+ // The text shown if you add a greeting item to the layout.
32+ nightGreeting : "Good night."
33+ , morningGreeting : "Good morning."
34+ , afternoonGreeting : "Good afternoon."
35+ , eveningGreeting : "Good evening."
36+
37+ // The text shown if you add a future weather item to the layout, or tomorrow's events.
38+ , nextHourLabel : "Next hour"
39+ , tomorrowLabel : "Tomorrow"
40+
41+ // The text shown in an events item when no events remain.
42+ // Change to blank "" if you don't want to show a message.
43+ , noEventMessage : "Enjoy the rest of your day."
3744
3845}
3946
@@ -494,7 +501,7 @@ function enumerateEvents() {
494501 if ( ! multipleTomorrowEvents ) {
495502
496503 // The tomorrow label is pretending to be an event.
497- returnedEvents . push ( { title : localeString . tomorrowStr ( ) . toUpperCase ( ) , isAllDay : true , isLabel : true } )
504+ returnedEvents . push ( { title : localizedText . tomorrowLabel . toUpperCase ( ) , isAllDay : true , isLabel : true } )
498505 multipleTomorrowEvents = true
499506 }
500507
@@ -633,9 +640,8 @@ function alignCenter(alignmentStack) {
633640// Display the date on the widget.
634641function date ( column ) {
635642
636- // Set up the date formatter.
643+ // Set up the date formatter and set its locale .
637644 let df = new DateFormatter ( )
638-
639645 df . locale = locale
640646
641647 // Show small if it's hard coded, or if it's dynamic and events are visible.
@@ -668,11 +674,11 @@ function greeting(column) {
668674 // This function makes a greeting based on the time of day.
669675 function makeGreeting ( ) {
670676 const hour = currentDate . getHours ( )
671- if ( hour < 5 ) { return localeString . goodnightStr ( ) }
672- if ( hour < 12 ) { return localeString . goodmorningStr ( ) }
673- if ( hour - 12 < 5 ) { return localeString . goodafternoonStr ( ) }
674- if ( hour - 12 < 10 ) { return localeString . goodeveningStr ( ) }
675- return localeString . goodnightStr ( )
677+ if ( hour < 5 ) { return localizedText . nightGreeting }
678+ if ( hour < 12 ) { return localizedText . morningGreeting }
679+ if ( hour - 12 < 5 ) { return localizedText . afternoonGreeting }
680+ if ( hour - 12 < 10 ) { return localizedText . eveningGreeting }
681+ return localizedText . nightGreeting
676682 }
677683
678684 // Set up the greeting.
@@ -686,7 +692,7 @@ function greeting(column) {
686692function events ( column ) {
687693
688694 // If nothing should be displayed, just return.
689- if ( ! eventsAreVisible && ! localeString . noEventMessage ( ) . length ) { return }
695+ if ( ! eventsAreVisible && ! localizedText . noEventMessage . length ) { return }
690696
691697 // Set up the event stack.
692698 let eventStack = column . addStack ( )
@@ -696,7 +702,7 @@ function events(column) {
696702
697703 // If there are no events, show the message and return.
698704 if ( ! eventsAreVisible ) {
699- let message = eventStack . addText ( localeString . noEventMessage ( ) )
705+ let message = eventStack . addText ( localizedText . noEventMessage )
700706 formatText ( message , textFormat . greeting )
701707 eventStack . setPadding ( 10 , 10 , 10 , 10 )
702708 return
@@ -816,7 +822,7 @@ function future(column) {
816822 const showNextHour = ( currentDate . getHours ( ) < tomorrowShownAtHour )
817823
818824 // Set the label value.
819- const subLabelText = showNextHour ? localeString . nexthourStr ( ) : localeString . tomorrowStr ( )
825+ const subLabelText = showNextHour ? localizedText . nextHourLabel : localizedText . tomorrowLabel
820826 let subLabelStack = align ( futureWeatherStack )
821827 let subLabel = subLabelStack . addText ( subLabelText )
822828 formatText ( subLabel , textFormat . smallTemp )
0 commit comments