Skip to content
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

Merged
merged 9 commits into from
Dec 12, 2023

Conversation

queeniechen-okta
Copy link
Contributor

@queeniechen-okta queeniechen-okta commented Dec 4, 2023

OKTA-671253

Summary

  • Got rid of the hardcoded supportedLanguages list
  • Update types for the above change
  • Add ability to bring custom language translations for existing keys
  • Update ok-SK/ ok-PL file & added instructions on how to do so

Type behaviour

With additional types:
Screenshot 2023-12-04 at 3 40 50 PM

Normal:
Screenshot 2023-12-04 at 3 42 10 PM

Testing & Screenshots

  • I have confirmed this change with my designer and the Odyssey Design Team.

children: ReactNode;
};

const OdysseyProvider = ({
const OdysseyProvider = <SupportedLanguages extends string>({
Copy link
Contributor Author

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: `.
Copy link
Contributor Author

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">
Copy link
Contributor Author

@queeniechen-okta queeniechen-okta Dec 4, 2023

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 = {
Copy link
Contributor Author

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. : )

Copy link
Contributor

@nikhilvenkatraman-okta nikhilvenkatraman-okta Dec 4, 2023

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2023-12-05 at 9 55 56 AM

There will be a typescript error :)

@@ -86,7 +82,6 @@ i18n.use(initReactI18next).init({
defaultNS,
ns: [defaultNS],
fallbackLng: defaultLNG,
supportedLngs: supportedLanguages,
Copy link
Contributor Author

@queeniechen-okta queeniechen-okta Dec 4, 2023

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

@queeniechen-okta queeniechen-okta force-pushed the OKTA-671253-fix-language-codes branch from 5d611d1 to 9eeaeb4 Compare December 4, 2023 21:11
translationOverrides: TranslationOverrides
) => {
const bundle = resources[languageCode];
const bundle = resources[languageCode] || {};
const overrides = translationOverrides[languageCode];
Copy link
Contributor Author

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? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

checked & it looks like you can perform the spread operation without issues on an undefined value. Interesting

Screenshot 2023-12-05 at 10 05 53 AM

@queeniechen-okta queeniechen-okta force-pushed the OKTA-671253-fix-language-codes branch from 9eeaeb4 to 83c0ed9 Compare December 4, 2023 21:46
@@ -25,14 +25,17 @@ import {
OdysseyTranslationProvider,
OdysseyTranslationProviderProps,
} from "./OdysseyTranslationProvider";
import { OktaSupportedLanguages } from "./OdysseyTranslationProvider.types";
Copy link
Contributor

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,
Copy link
Contributor

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 ?

Copy link
Contributor Author

@queeniechen-okta queeniechen-okta Dec 5, 2023

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

Copy link
Contributor

@benschell-okta benschell-okta left a 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.

Copy link
Contributor

@KevinGhadyani-Okta KevinGhadyani-Okta left a 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.

@queeniechen-okta queeniechen-okta force-pushed the OKTA-671253-fix-language-codes branch from c0cb98a to 43ce779 Compare December 11, 2023 21:39
@queeniechen-okta queeniechen-okta merged commit f371f3c into main Dec 12, 2023
1 check passed
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.

5 participants