-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OKTA-671253: Allow language codes other than okta specified ones #2058
Conversation
4139edc
to
5d611d1
Compare
children: ReactNode; | ||
}; | ||
|
||
const OdysseyProvider = ({ | ||
const OdysseyProvider = <SupportedLanguages extends string>({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, this does not force anyone to pass a generic EVERY time because we have a default value further down
|
||
Right now we do not have the code to generate these files in Odyssey. | ||
|
||
If you are an Okta employee, the easiest way to generate these files is to replace the English properties file of another project and run the build commands to get the ok-PL and ok-SK versions. For ok-SK, you will also need to replace the prefix with `odyssey:odyssey-react-mui: `. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not optimal but we have a JIRA to address this here: https://oktainc.atlassian.net/browse/OKTA-622636
@@ -26,6 +26,38 @@ describe("OdysseyTranslationProvider", () => { | |||
expect(screen.getByText("Optional")); | |||
}); | |||
|
|||
it("defaults to 'en' for unsupported langauges", () => { | |||
render( | |||
<OdysseyTranslationProvider<"ar" | "yi"> languageCode="ar"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, languageCode
has type string
by inference if you have <OdysseyTranslationProvider ...>
WITHOUT specifying a specific list. (which is weird if you think about how it is typed down the road)
however, upon specifying a specific list, it will complain if your constant is not exactly a value in that list
export const defaultNS = "translations"; | ||
export const resources = { | ||
export type OktaI18nResources = Record<string, typeof en>; | ||
export const resources: OktaI18nResources = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this allows us to detect when ok-PL
and ok-SK
files are out of sync with the rest. : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this allows us to detect when ok-PL and ok-SK files are out of sync with the rest. : )
Nice I am curious, what this experience looks like for a dev.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -86,7 +82,6 @@ i18n.use(initReactI18next).init({ | |||
defaultNS, | |||
ns: [defaultNS], | |||
fallbackLng: defaultLNG, | |||
supportedLngs: supportedLanguages, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleting this just means we will try and load any language. As shown in the test, i the language is not supported properly (i.e. doesnt have the proper resources) it defaults to english
5d611d1
to
9eeaeb4
Compare
translationOverrides: TranslationOverrides | ||
) => { | ||
const bundle = resources[languageCode]; | ||
const bundle = resources[languageCode] || {}; | ||
const overrides = translationOverrides[languageCode]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wondering if I should make it error i the override isn't found? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9eeaeb4
to
83c0ed9
Compare
@@ -25,14 +25,17 @@ import { | |||
OdysseyTranslationProvider, | |||
OdysseyTranslationProviderProps, | |||
} from "./OdysseyTranslationProvider"; | |||
import { OktaSupportedLanguages } from "./OdysseyTranslationProvider.types"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think we'd want to avoid including Okta
in the import naming convention here(And in other locations in this PR). As Odyssey is open source and potentially used outside of the context of Okta.
[key in SupportedLanguages]?: Partial<(typeof resources)["en"]>; | ||
}; | ||
export type TranslationOverrides = Record< | ||
string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this mainly to allow any keys that will be defined in a locale bundle that is not in the supported list ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, the key( typed string
) part of this is.
the value type with partial is here so that you can choose to provide a subset of keys.
Otherwise if we use the typing from the i18n.ts
file, we will need to provide ALL keys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know Kevin and Chris are both unavailable today. This looks great to me, so approving. If any issues are found or if Kevin or Chris end up having other opinions, we'll fix-forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great PR! Thanks for contributing :).
We discussed any weird stuff on Zoom already.
c0cb98a
to
43ce779
Compare
OKTA-671253
Summary
Type behaviour
With additional types:
![Screenshot 2023-12-04 at 3 40 50 PM](https://private-user-images.githubusercontent.com/83596595/287835275-020f6a47-ca74-4efe-a10f-e00ffd79bc9e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0MjgzNDYsIm5iZiI6MTczOTQyODA0NiwicGF0aCI6Ii84MzU5NjU5NS8yODc4MzUyNzUtMDIwZjZhNDctY2E3NC00ZWZlLWExMGYtZTAwZmZkNzliYzllLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDA2MjcyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTMyMjNjYWQxZDUwZGY0YWRhZTc5MjEzNTQwYzhkNjBiOWQ0YzhlMDA5ZGM1ZDE1MDI2Mzc3ZWM2MTJiZWNmNDcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.auz1re-D69P9hYuXQUPaRs20-x2JQCvj3pTi_Q81ISs)
Normal:
![Screenshot 2023-12-04 at 3 42 10 PM](https://private-user-images.githubusercontent.com/83596595/287835290-b6075b7b-79a9-46cd-8d05-8f5084ef464e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0MjgzNDYsIm5iZiI6MTczOTQyODA0NiwicGF0aCI6Ii84MzU5NjU5NS8yODc4MzUyOTAtYjYwNzViN2ItNzlhOS00NmNkLThkMDUtOGY1MDg0ZWY0NjRlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDA2MjcyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc0ZGFhM2JlMGY2YWQ1OTM4ZWY4YjA2MmFmZDUwMmFkYTQ1NGU4OGZiMWJiYTAzNzBlNzk2MGMwYzU4NmM3MTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.ksG1Kjt73lw3ukWA4EFhZoApipLWKrqLFj0dNickBxo)
Testing & Screenshots