Skip to content

Conversation

mportiz08
Copy link
Contributor

Bug/issue #, if applicable: 149303906

Summary

The availableLocales Render JSON key may be renamed to availableLanguages going forward, although we still want to support both keys for maximum compatibility with older JSON (preferring the new one if both are present for some reason).

Testing

Steps:

  1. Verify that the key availableLanguages can be used in place of availableLocales

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran npm test, and it succeeded
  • Updated documentation if necessary

Copy link
Member

@marinaaisa marinaaisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Marcus!

I left some refactoring ideas and suggestions, everything else looks great, thank you!

Comment on lines 179 to +185
'metadata.availableLocales': function availableLocalesWatcher(availableLocales) {
AppStore.setAvailableLocales(availableLocales);
AppStore.setAvailableLocales(this.metadata?.availableLanguages ?? availableLocales);
},
'metadata.availableLanguages': function availableLanguagesWatcher(availableLanguages) {
AppStore.setAvailableLocales(availableLanguages);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could refactor this code by adding a computed property:

availableLanguages: ({ metadata: { availableLanguages, availableLocales } = {} }) => (
  availableLanguages ?? availableLocales
),

and then just watch that computed property like:

watch: {
  availableLanguages(newValue) {
    AppStore.setAvailableLocales(newValue);
  },
},

instead of watching 'metadata.availableLocales' and 'metadata.availableLanguages'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the existing logic could be refactored and improved to be better and more consistent, but I was mostly focused on making the minimal changes to minimize the surface area of changes overall.

Thanks for the suggestion! It might be good to make those changes afterwards.

Comment on lines 147 to +153
'metadata.availableLocales': function availableLocalesWatcher(availableLocales) {
AppStore.setAvailableLocales(availableLocales);
AppStore.setAvailableLocales(this.metadata?.availableLanguages ?? availableLocales);
},
'metadata.availableLanguages': function availableLanguagesWatcher(availableLanguages) {
AppStore.setAvailableLocales(availableLanguages);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same feedback about the computed property as before

Comment on lines 113 to +119
'metadata.availableLocales': function availableLocalesWatcher(availableLocales) {
AppStore.setAvailableLocales(availableLocales);
AppStore.setAvailableLocales(this.metadata?.availableLanguages ?? availableLocales);
},
'metadata.availableLanguages': function availableLanguagesWatcher(availableLanguages) {
AppStore.setAvailableLocales(availableLanguages);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same feedback about the computed property as before

Comment on lines +738 to +742
availableLanguages(availableLanguages) {
AppStore.setAvailableLocales(availableLanguages);
},
availableLocales(availableLocales) {
AppStore.setAvailableLocales(availableLocales);
AppStore.setAvailableLocales(this.availableLanguages ?? availableLocales);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar feedback:

We could make a computed property like

resolvedAvailableLanguages({ availableLanguages, availableLocales }) {
  return availableLanguages ?? availableLocales;
}

and then have a watcher like

watch: {
  resolvedAvailableLanguages(newValue) {
    AppStore.setAvailableLocales(newValue);
  },
},

on created(), we could also simplify it by:

AppStore.setAvailableLocales(this.resolvedAvailableLanguages);

Copy link
Member

@marinaaisa marinaaisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving it since it works well!

@mportiz08
Copy link
Contributor Author

@swift-ci test

@mportiz08 mportiz08 merged commit 01077a0 into swiftlang:main Oct 8, 2025
1 check passed
@mportiz08 mportiz08 deleted the support-available-languages-key branch October 8, 2025 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants