2525import com .vaadin .flow .component .dependency .JsModule ;
2626import com .vaadin .flow .component .dependency .NpmPackage ;
2727import com .vaadin .flow .dom .Element ;
28+ import com .vaadin .flow .internal .JsonSerializer ;
29+
30+ import java .io .Serializable ;
31+ import java .util .Objects ;
2832
2933/**
3034 * A side navigation menu with support for hierarchical and flat menus.
@@ -42,6 +46,8 @@ public class SideNav extends SideNavItemContainer implements HasSize, HasStyle {
4246
4347 private Element labelElement ;
4448
49+ private SideNavI18n i18n ;
50+
4551 /**
4652 * Creates a new menu without any label.
4753 */
@@ -151,6 +157,35 @@ protected void onAttach(AttachEvent attachEvent) {
151157 checkFeatureFlag ();
152158 }
153159
160+ /**
161+ * Gets the internationalization object previously set for this component.
162+ * <p>
163+ * Note: updating the object content that is gotten from this method will
164+ * not update the lang on the component if not set back using
165+ * {@link SideNav#setI18n(SideNavI18n)}
166+ *
167+ * @return the i18n object. It will be <code>null</code>, If the i18n
168+ * properties weren't set.
169+ */
170+ public SideNavI18n getI18n () {
171+ return i18n ;
172+ }
173+
174+ /**
175+ * Updates the i18n settings in the web component. Merges the
176+ * {@link SideNavI18n} settings with the current / default settings of the
177+ * web component.
178+ *
179+ * @param i18n
180+ * the internationalized properties, not <code>null</code>
181+ */
182+ public void setI18n (SideNavI18n i18n ) {
183+ Objects .requireNonNull (i18n ,
184+ "The i18N properties object should not be null" );
185+ this .i18n = i18n ;
186+ getElement ().setPropertyJson ("i18n" , JsonSerializer .toJson (i18n ));
187+ }
188+
154189 /**
155190 * Checks whether the SideNav component feature flag is active. Succeeds if
156191 * the flag is enabled, and throws otherwise.
@@ -180,4 +215,33 @@ protected FeatureFlags getFeatureFlags() {
180215 .get (UI .getCurrent ().getSession ().getService ().getContext ());
181216 }
182217
218+ /**
219+ * The internationalization properties for {@link SideNav}.
220+ */
221+ public static class SideNavI18n implements Serializable {
222+ private String toggle ;
223+
224+ /**
225+ * The text announced by screen readers when focusing the button for
226+ * toggling child items.
227+ *
228+ * @return the translated expression for toggling child items
229+ */
230+ public String getToggle () {
231+ return toggle ;
232+ }
233+
234+ /**
235+ * Sets the text announced by screen readers when focusing the button
236+ * for toggling child items.
237+ *
238+ * @param toggle
239+ * the translated expression for toggling child items
240+ * @return this instance for method chaining
241+ */
242+ public SideNavI18n setToggle (String toggle ) {
243+ this .toggle = toggle ;
244+ return this ;
245+ }
246+ }
183247}
0 commit comments