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

add ts support for i18n strings #217

Merged
merged 17 commits into from
Feb 4, 2025

Conversation

warm-coolguy
Copy link
Member

@warm-coolguy warm-coolguy commented Jan 16, 2025

Summary

  • Rename all locale files to language.ts
    • I don't really like the name, but it was the smaller change for now; i18next seems to name these files locales according to this example folder structure; maybe all files should be named locales.ts instead? Asking for approval before changing, please block or confirm this effort.
  • Removed all the nested tsconfig.json. This enabled $t('') support in templates for me, so I assume something was wrong with them anyway and TS now falls back to the global tsconfig.json when doing anything.
  • Globally removed the common: prefix since we don't have multiple namespaces and common: is the default namespace anyway, so even if we move ahead to add additional namespaces, there is no need to add the prefix.

Instructions for local reproduction and review

  • Dev side: Test whether $t('') breaks in vue and i18n.$t('') breaks outside of vue. Since '' is not a valid locale string, both should fail, id est throw some sort of error in your IDE (and, outside of .vue files, in the type check). You should also get autocompletion when typing out a new $t statement.
  • Dev side: Check if I broke anything by removing the nested tsconfig.json files. Seems to just work to me.
  • User side: Test all locale files for i18n connection correctness. We don't need to see all keys interpreted, one key per package should suffice.

Caveats

  • I absolutely reassured typescript that e.g. Snowbox Locale Keys are now available in every plugin, which is plain wrong. However, there seems to be no simple way to have local overrides of the i18n module definition per package, so I consider this good enough.
  • I didn't fix type errors in clients' .vue files 100% and some edge cases in clients remain where a calculated locale keys (e.g. something.${string}) do not match the pattern (type is a generic string), but work perfectly fine nonetheless. Since TS is not well-supported in Vue@2 anyway and lots of errors remain, I don't really think that detail's worth the effort.

Relevant tickets, issues, et cetera

Resolves: #94

@warm-coolguy warm-coolguy added the refactor Refactoring of previous code label Jan 16, 2025
@warm-coolguy warm-coolguy self-assigned this Jan 16, 2025
@warm-coolguy warm-coolguy force-pushed the dx/#94-add-ts-support-for-i18n-strings branch from 6830c9d to fd72335 Compare January 16, 2025 06:29
@warm-coolguy
Copy link
Member Author

warm-coolguy commented Feb 3, 2025

TODO: #216 (review)

  • Rename language.ts to locale.ts locales.ts
  • Rename LanguageOption to Locale?

the word "language" had double usage; on the one
hand for actual translations, on the other for a
chosen language (like "en")

this has been separated by this commit, actual
translations are now referred to as "locales"

this changes the PLUGIN API (BREAKING)
@warm-coolguy
Copy link
Member Author

TODO: #216 (review)

* Rename `language.ts` to ~`locale.ts`~ `locales.ts`

* Rename `LanguageOption` to `Locale`?

🏓 @dopenguin

The transferred TODOs have been adressed and this PR is ready for review. Since it introduces breaking changes, I advise to merge it before we do the breaking change regarding OL to have it released in the same cycle.

Copy link
Member

@dopenguin dopenguin left a comment

Choose a reason for hiding this comment

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

Personally, I'm not really a fan of loosing the history of a file but it seems negligible for the locales and probably more of a hazzle to preserve it so it seems the way to go.

The autocompletion works like a charm in most files but I don't seem to get it running in any .vue-files. I also have errors constantly being displayed inline about a type mismatch (like before). Did you add any configurations to your IDE for it to work in .vue-files?

I also think its a bit irritating that you (justly) removed all common-namespace-prefixes but the autocompletion adds the namespace on autocompletion. Do you know if that can be configured or that is something we simply have to live with?

The removal of all tsconfig.json-files seems to be of no problem, as far as I can tell. If I add a TS error, the respective command still informs me of said error.

🏓 @warm-coolguy

scripts/makeDocs.ts Show resolved Hide resolved
packages/types/custom/core.ts Show resolved Hide resolved
packages/lib/tooltip/index.ts Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
packages/core/src/components/MapContainer.vue Outdated Show resolved Hide resolved
packages/clients/meldemichel/src/mapConfigurations.ts Outdated Show resolved Hide resolved
@types/i18next.d.ts Outdated Show resolved Hide resolved
warm-coolguy and others added 3 commits February 4, 2025 07:18
apply suggestion "consistently rename lng"

Co-authored-by: Pascal Röhling <73653210+dopenguin@users.noreply.github.com>
apply suggestion "shorten expression"

Co-authored-by: Pascal Röhling <73653210+dopenguin@users.noreply.github.com>
@warm-coolguy
Copy link
Member Author

Personally, I'm not really a fan of loosing the history of a file but it seems negligible for the locales and probably more of a hazzle to preserve it so it seems the way to go.

Did we really lose it? In the commit, it looks like git realized the files were merely renamed: 57eabf3#diff-f5ec52c63439dddd1ea390e39d788dcef27be3a556007a80dc0d3b3328ab7b33

The autocompletion works like a charm in most files but I don't seem to get it running in any .vue-files. I also have errors constantly being displayed inline about a type mismatch (like before). Did you add any configurations to your IDE for it to work in .vue-files?

No, I didn't change anything. But all .vue file support stops if I disable this vsc extension, so I guess that's somewhere under the hood there. The service reporting errors signs as ts-plugin.

I also think its a bit irritating that you (justly) removed all common-namespace-prefixes but the autocompletion adds the namespace on autocompletion. Do you know if that can be configured or that is something we simply have to live with?

My autocompletion doesn't do that.

🏓 @dopenguin

@dopenguin
Copy link
Member

Personally, I'm not really a fan of loosing the history of a file but it seems negligible for the locales and probably more of a hazzle to preserve it so it seems the way to go.

Did we really lose it? In the commit, it looks like git realized the files were merely renamed: 57eabf3#diff-f5ec52c63439dddd1ea390e39d788dcef27be3a556007a80dc0d3b3328ab7b33

Yeah, you're right. GitHub just displays is like that in the UI. If I look at the files in my IDE, it is fine.

The autocompletion works like a charm in most files but I don't seem to get it running in any .vue-files. I also have errors constantly being displayed inline about a type mismatch (like before). Did you add any configurations to your IDE for it to work in .vue-files?

No, I didn't change anything. But all .vue file support stops if I disable this vsc extension, so I guess that's somewhere under the hood there. The service reporting errors signs as ts-plugin.

Hm, that is kind of sad, that only VSC has that support. But maybe that will change with Vue@3 for me as well.

I also think its a bit irritating that you (justly) removed all common-namespace-prefixes but the autocompletion adds the namespace on autocompletion. Do you know if that can be configured or that is something we simply have to live with?

My autocompletion doesn't do that.

Hm, weird.

🏓 @dopenguin

🏓 @warm-coolguy

warm-coolguy and others added 2 commits February 4, 2025 10:18
apply suggestion "unify import"

Co-authored-by: Pascal Röhling <73653210+dopenguin@users.noreply.github.com>
@warm-coolguy
Copy link
Member Author

Personally, I'm not really a fan of loosing the history of a file but it seems negligible for the locales and probably more of a hazzle to preserve it so it seems the way to go.

Did we really lose it? In the commit, it looks like git realized the files were merely renamed: 57eabf3#diff-f5ec52c63439dddd1ea390e39d788dcef27be3a556007a80dc0d3b3328ab7b33

Yeah, you're right. GitHub just displays is like that in the UI. If I look at the files in my IDE, it is fine.

The autocompletion works like a charm in most files but I don't seem to get it running in any .vue-files. I also have errors constantly being displayed inline about a type mismatch (like before). Did you add any configurations to your IDE for it to work in .vue-files?

No, I didn't change anything. But all .vue file support stops if I disable this vsc extension, so I guess that's somewhere under the hood there. The service reporting errors signs as ts-plugin.

Hm, that is kind of sad, that only VSC has that support. But maybe that will change with Vue@3 for me as well.

I also think its a bit irritating that you (justly) removed all common-namespace-prefixes but the autocompletion adds the namespace on autocompletion. Do you know if that can be configured or that is something we simply have to live with?

My autocompletion doesn't do that.

Hm, weird.

🏓 @dopenguin

🏓 @warm-coolguy

🏓 @dopenguin ponging intensifies

Copy link
Member

@dopenguin dopenguin left a comment

Choose a reason for hiding this comment

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

Personally, I'm not really a fan of loosing the history of a file but it seems negligible for the locales and probably more of a hazzle to preserve it so it seems the way to go.

Did we really lose it? In the commit, it looks like git realized the files were merely renamed: 57eabf3#diff-f5ec52c63439dddd1ea390e39d788dcef27be3a556007a80dc0d3b3328ab7b33

Yeah, you're right. GitHub just displays is like that in the UI. If I look at the files in my IDE, it is fine.

The autocompletion works like a charm in most files but I don't seem to get it running in any .vue-files. I also have errors constantly being displayed inline about a type mismatch (like before). Did you add any configurations to your IDE for it to work in .vue-files?

No, I didn't change anything. But all .vue file support stops if I disable this vsc extension, so I guess that's somewhere under the hood there. The service reporting errors signs as ts-plugin.

Hm, that is kind of sad, that only VSC has that support. But maybe that will change with Vue@3 for me as well.

I also think its a bit irritating that you (justly) removed all common-namespace-prefixes but the autocompletion adds the namespace on autocompletion. Do you know if that can be configured or that is something we simply have to live with?

My autocompletion doesn't do that.

Hm, weird.

🏓 @dopenguin

🏓 @warm-coolguy

🏓 @dopenguin ponging intensifies

:shipit: @warm-coolguy

@warm-coolguy warm-coolguy merged commit f49f174 into main Feb 4, 2025
4 checks passed
@warm-coolguy warm-coolguy deleted the dx/#94-add-ts-support-for-i18n-strings branch February 4, 2025 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactoring of previous code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add enhanced typescript support for i18next string
2 participants