Refactor to TypeScript and Telegraf v4#40
Open
EdJoPaTo wants to merge 44 commits intotelegraf:developfrom
Open
Refactor to TypeScript and Telegraf v4#40EdJoPaTo wants to merge 44 commits intotelegraf:developfrom
EdJoPaTo wants to merge 44 commits intotelegraf:developfrom
Conversation
BREAKING CHANGES:
`const I18n = require()`
has to be rectored to
`const {I18n} = require()`
NodeJS 10 required now
The method loads the template for this resourceKey. Not having the resourceKey then seems useless. BREAKING CHANGE: resourceKey requires resourceKey If someone has a reason why thats needed it can be added again.
Contributor
Author
|
This Pull Request is now available as @edjopato/telegraf-i18n on npm. If you test it please report back to this Pull Request (like approving it) to increase confidence in a good end result. |
EdJoPaTo
added a commit
to EdJoPaTo/telegram-typescript-bot-template
that referenced
this pull request
Nov 8, 2020
…'s way (#1) * feat: templateData should be required as original version's way Co-authored-by: EdJoPaTo <[email protected]>
BREAKING CHANGE: requires telegraf v4 and NodeJS v12
|
@EdJoPaTo Using the following expression:
throws TS error: Using "telegraf": "^4.0.2" and "@edjopato/telegraf-i18n": "^0.2.0" |
ugly but works
Contributor
Author
Bumps [xo](https://github.com/xojs/xo) from 0.37.1 to 0.38.1. - [Release notes](https://github.com/xojs/xo/releases) - [Commits](xojs/xo@v0.37.1...v0.38.1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
use typegram directly
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.43 to 15.0.1. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 9.1.1 to 10.0.0. - [Release notes](https://github.com/TypeStrong/ts-node/releases) - [Commits](TypeStrong/ts-node@v9.1.1...v10.0.0) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [del-cli](https://github.com/sindresorhus/del-cli) from 3.0.1 to 4.0.0. - [Release notes](https://github.com/sindresorhus/del-cli/releases) - [Commits](sindresorhus/del-cli@v3.0.1...v4.0.0) --- updated-dependencies: - dependency-name: del-cli dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 15.14.1 to 16.0.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [xo](https://github.com/xojs/xo) from 0.41.0 to 0.42.0. - [Release notes](https://github.com/xojs/xo/releases) - [Commits](xojs/xo@v0.41.0...v0.42.0) --- updated-dependencies: - dependency-name: xo dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
BREAKING CHANGE: this removes the helper match and reply. They arnt used that often anyway and would have made compatibilty with grammY harder.
Contributor
Author
|
This pull request is now available as https://github.com/grammyjs/i18n and works with both grammY and Telegraf. I will leave it open so its easier to see for everyone coming by. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request refactors the code to TypeScript.
This has the benefit of not having separate typings which are maybe wrong. This should also improve code readability and maintainability.
While this should be a simple refactoring in general I decided to introduce two changes to simplify code and have more strict typings, one change is breaking.
The first change is the internal structure of the locale repositories. Before this change the Repository is structured with the object tree structure. When the
resourceKeya.b.cin languageenis requested the following value is read:{en: {a: {b: {c: value}}}}.With this change the dot notation is already applied when loading into the repository and not every time a key is used. This results in a simpler structure of the repository:
{en: {'a.b.c': value}}. Having that simplifies internal typings (and has an insignificant performance benefit). This change is not breaking and shouldn't be noticed by users.The breaking change is the way to import/require and use this library.
Before this you could simply use any name you liked and use that:
With these changes you always have to use it like this:
Allowing for the default import is not as easy with ES6 and CommonJS style imports and having the I18n class and functions like
reply. After some testing it wasnt worth my time: There is a way to use it and its not hard to adapt to that.If someone has some suggestions how to solve that elegantly: I'm curious :)
As NodeJS 8 is not supported anymore and telegraf now requiring NodeJS 12 this is also another breaking change. But as you need NodeJS 12 or higher for telegraf anyway users probably wont notice.
fixes #30
fixes #33
fixes #35
fixes #36
fixes #37
fixes #38
Feel free to comment on the changes. I'm sure someone can spot something to improve or has better ideas how to do something.
I tested the changes in multiple of my TypeScript Bots. I do not have any running JavaScript bot left so it might be nice if someone else is willing to test on that. Especially If the import works well.