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

Entity Language Type is incorrect #107

Open
EdJoPaTo opened this issue Mar 13, 2023 · 1 comment
Open

Entity Language Type is incorrect #107

EdJoPaTo opened this issue Mar 13, 2023 · 1 comment

Comments

@EdJoPaTo
Copy link
Contributor

  • wikibase-sdk version: 9.0.5
  • Environment: 19.7.0

Currently the Entity Type for labels, description, aliases and so on is Record<WmLanguageCode, …>. WmLanguageCode is only de but not something like de-ch which is also there.

Not sure how to model all the possible variations there or just to use string or type LanguageCode = string to help with code reading?

@EdJoPaTo
Copy link
Contributor Author

Maybe something like this?

/** Language code like de, en, fr but not de-ch */
type WmLanguageCode = typeof languages[number] // generated by script
/** Language variant like de-ch */
type WmLanguageVariant = string // not sure if that's something possible to be scripted

/** Language codes and language variants like de, de-ch, en, fr */
type WmLanguage = WmLanguageCode | WmLanguageVariant // something | string will be simplified to be string currently but its still better to use internally to understand what kind of string it is

Interestingly there is shortLang which splits at _ and not - which is used on labels, descriptions and so on. So probably both cases exist. Should be care about that or should we just use one type for both?

/** Example: keep only 'fr' in 'fr_FR' */
export function shortLang (language: string): WmLanguageCode {
const lang = language.toLowerCase().split('_')[0] as WmLanguageCode
return lang
}

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 a pull request may close this issue.

1 participant