Election-Tech-Initiative/electionguard-ui

โœจ Isolate Language Component in Library

Closed this issue ยท 5 comments

Is there an existing issue for this?

  • I have searched the existing issues

Suggestion

The json files in lang in library should be within the app projects.

For example

๐Ÿ“‚ admin-app
    ๐Ÿ“‚ src
         ๐Ÿ“‚ lang
             en.json
             MessageId.ts
๐Ÿ“‚ result-app
    ๐Ÿ“‚ src
         ๐Ÿ“‚ lang
             en.json
             MessageId.ts

This actually means a lot of changes on the BaseComponents to allow this. The idea is to create a Language component that can be reused without duplicating code between the app applications.
Screen Shot 2021-09-30 at 3 58 27 PM

Possible Implementation

Example of a Generic Message

import { MessageDescriptor } from '@formatjs/intl';

const OverloadMessageId = 'overload';

const PlaceHolderMessageId = 'placeholder';

const placeholderMessage = 'Message Not Found';

export default class GenericMessage<T extends string | number> implements MessageDescriptor {
    id: T | typeof OverloadMessageId | typeof PlaceHolderMessageId;

    defaultMessage: string;

    description?: string;

    constructor(
        id: T | typeof OverloadMessageId | typeof PlaceHolderMessageId = PlaceHolderMessageId,
        defaultMessage = placeholderMessage,
        description?: string
    ) {
        this.id = id;
        this.defaultMessage = defaultMessage;
        this.description = description;
    }
}

export type GenericMessageDescriptor = MessageDescriptor;

Example of a generic piece to pull the languages from library.

import EnumDictionary from '@electionguard-ui/library/src/utils/EnumDictionary';

import Locale from './Locale';
import Language from './Language';

/**
 * Get language for locale based on list of supported languages
 * @param supportedLanguages
 * @returns Language
 */
const getLanguage = (supportedLanguages: EnumDictionary<Locale, Language>): Language => {
    const locale = navigator.language;

    if (locale in Locale) {
        return supportedLanguages[locale as Locale];
    }

    return supportedLanguages.default;
};

export default getLanguage;

Anything else?

No response

@keithrfung I'd like to pick this up as well, can you assign this to me?

@deepto98 you got it

@deepto98 How is the progress on this? I have a couple issues I want to assign that depend on this.

@keithrfung Hi, I've set up the project locally, but was a bit busy with work through the week. I'll try to get this done today, and will keep you updated

@deepto98 I'm gonna pick up this card because we need to push this piece through for some more work