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

Templates for Internalization (messages, formatting) #138

Open
4 tasks
jozef-slezak opened this issue Jul 1, 2021 · 0 comments
Open
4 tasks

Templates for Internalization (messages, formatting) #138

jozef-slezak opened this issue Jul 1, 2021 · 0 comments

Comments

@jozef-slezak
Copy link
Contributor

jozef-slezak commented Jul 1, 2021

Goal: Refactor existing internalization code from ts.factory*() to templates

Background: we believe it is more intuitive to extend and maintain the codegen functionality using templates (rather then typescript factories). Typescript factory code builds AST using code but it tends to be hard to read once you get to bigger code snippet. We have tried different approach: we parse source file (template) as an AST and then apply refactoring rules like here https://github.com/iteria-app/lowcode/blob/master/packages/react-lowcode/src/codegen/generation/generators/template/template-resolver.ts

How to do that?

  • keep existing interfaces / API
  • introduce new implementation of the API using templates + refactoring rules
  • check that existing jest test are still green (after switching implementation)

The template source file:

  1. template should be normal normal working code
  2. refactoring rules should inline function from the template to the target/generated code
  3. template should look like this:

different templates for: react-intl or standard browser Intl:

export formatNumberPlaceholder() {
   return usage of react-intl format
}

export formatDatePlaceholder(todo params) {
   return usage of react-intl format
}

export formatTimePlaceholder(todo params) {
   return usage of react-intl format
}

Different template for react-intl or react-i18n

//react-intl.ts
export function T(messageID, defaultMessage) {
   const intl = useIntl()
   return intl.formatMessage(messageID, defaultMessage)
}

//similarly react-i18n.ts


// dummy-intl.ts
// this function will be replaced by `intl.`
export function T(messageID, defaultMessage) {
  return defaultMessage || messageID // default dummy implementation (without any framework )
}

export TranslatePlaceholder // TODO react tag code, params messageID
   return <FormattedMessage ... tag="span" />
}

What to do?

Checklist:

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

No branches or pull requests

1 participant