-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Refactor i18n #1405
Refactor i18n #1405
Conversation
- typings do not work for any ts or svelte files - if we set the 'rootDirs' in ts/tsconfig.json to '../bazel-bin/ts' and then inherit them from e.g. editor, the root will be changed to '../../bazel-bin/ts', however editor needs look in '../../bazel-bin/ts/editor' instead.
- This way, we can restrict the awkwardness of importing files outside the ts directory within lib
Strange, the typings are working fine for me. I have the latest "Svelte for VS Code" installed ( v105.4.1 ) and start it by opening the root Anki folder after building with 'bazel build //...' to ensure all the Svelte files have been generated. Might be worth trying a 'bazel clean' to clear out old files that are in the wrong location, and making sure you're opening the base folder rather than just a single subfolder? I don't mind the rootDir change if it doesn't break anything, but would like to understand what's wrong first. The reason for the current i18n layout is because rexporting symbols breaks tree shaking:
I agree the current layout is a bit awkward, and no objections from me on a change if you can preserve the tree shaking aspect. |
This partially reverts commit e1d4292. It seems like this might not be necessary after all. However some other change made on this branch seems to have fixed the .svelte.d.ts imports
There was a circular import i18n.ts <-> i18n-translate.ts
* This restores tree shaking
* es2018-2020 have wide support on all modern browsers including
a0ab15f
to
72256f0
Compare
Here the author of esbuild himself says it:
I've done several I also changed tsconfig's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor looks good; some comments below.
I'm still puzzled by this symlink requirement though. Will test on another machine and get back to you.
ts/tsconfig.json
Outdated
"dom.iterable" | ||
], | ||
"module": "es2020", | ||
"lib": ["es2020", "dom", "dom.iterable"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this safe? The current minimum Qt target is 5.14, which is Chromium 77 - which does not support things like the nullish coalescing operator. Neither does iOS 12 / early iOS 13.
Does this change enable something important that we were missing, or was it just about making things neater?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case no, I'll revert it. I only needed to add support for .fromEntries
.
Is there some reference list of platforms Anki aims to support. I basically went through the lists on icanuse
and looked out for:
- support for Chromium 83
- support for iOS 14/15
in which case we could go with es2020.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently it's Chromium 77/iOS 12
- iOS 12 support will likely be dropped soon, but I try to support a few versions back, so I'd like to retain 13 support unless there's a compelling reason for dropping it early
- The current Windows and Mac builds use Qt 5.14 due to bugs in 5.15 (5.15 is only used when running from Bazel). Ideally we would drop 5.x support once the 6.2 branch is polished, but in past Qt updates, newer versions have broken things for some users. We'll know more once 6.2 has been polished a bit and has a packaged build available, but I wouldn't be surprised if we end up needing to bring back alternate versions based on 5.x for users that have trouble with the 6.2 build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(it might be worth setting up eslint to warn us when we use something outside those versions - feel free to look into that if you're interested :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#982 tracks the 5.15 issues
Ok:
Any ideas about the DynamicSvelteComponent issues in DeckOptionsPage? |
I suspect this is caused by our node_modules being in ts/ instead of the root folder. With a symlink all files stay in ts, but when we reference ../../bazel-bin it presumably hunts further up the tree, and results in it not being able to find libraries like 'svelte', breaking the definitions. Will look into moving the location tomorrow and see if it helps |
I think you might be right. According to this StackOverflow answer:
So this means that our inferred |
I added them to fix to have completion for tr, however this would have also have meant to abandon the tree shaking. As we want to have tree shaking, it's also not necessary to have the symlinks anymore
This reverts commit 0a96776.
ts/tsconfig.json
Outdated
@@ -33,7 +34,6 @@ | |||
// "rootDir": "..", | |||
"rootDir": ".", | |||
"rootDirs": [ | |||
".", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, everything in this PR everything except removing this line is just refactoring i18n into a directory.
Removing this line is what fixes autocompletion for Svelte components for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately that didn't work for me - I tried the latest code in this PR, and the generated i18n files can't be found by vscode on my machine.
Moving node_modules to the root folder and setting rootDir to .. seems to solve things - could you give #1408 a try? If that works, we can just drop the rootDirs change from this PR and it should be good to merge in.
Recommend removing ts/node_modules folder before attempting to build after this update. This moves ts/node_modules into the root of the project to work around #1405 (comment) Also fixes the sass errors shown when running scripts/svelte-check
Recommend removing ts/node_modules folder before attempting to build after this update. This moves ts/node_modules into the root of the project to work around #1405 (comment) Also fixes the sass errors shown when running scripts/svelte-check
Want to squash and rebase this over main so we get a nice clean commit? :-) |
Sounds good :) |
Sorry, that wasn't clear. I'd meant to suggest you do that (so we can test it over main the main branch before merging in - if I squashed it with the git interface it would presumably show up as authored by me instead). But I didn't want to hold this up and we've tested it already, so I just used GitHub's 'squash and merge' this time |
I did get you, I was just about to push the squashed commit :) I'll also try to be more clear next time. |
All good :-) |
* Only collect card stats on the backend ... ... instead of rendering an HTML string using askama. * Add ts page Card Info * Update test for new `col.card_stats()` * Remove obsolete CardStats code * Use new ts page in `CardInfoDialog` * Align start and end instead of left and right Curiously, `text-align: start` does not work for `th` tags if assigned via classes. * Adopt ts refactorings after rebase #1405 and #1409 * Clean up `ts/card-info/BUILD.bazel` * Port card info logic from Rust to TS * Move repeated field to the top #1414 (comment) * Convert pseudo classes to interfaces * CardInfoPage -> CardInfo * Make revlog in card info optional * Add legacy support for old card stats * Check for undefined instead of falsy * Make Revlog separate component * drop askama dependency (dae) * Fix nightmode for legacy card stats
Moving to
ts_project
has broken types for me on both VS Code and Neovim. This is an error message:This PR fixes types for me. Obviously we should find a solution that fixes it for everybody :)
To fix the typings for svelte files, I had to move the
rootDirs
parameter inside the sub projects.To fix the typings for
tr
andbackend_proto
I had to reinstate the symlinks you originally had added.I also used the opportunity to rewrite
i18n
quite a bit. The oldi18n_helpers
is now the maini18n
file. As the generated files are more difficult to handle, I thought it would make more sense, if the other subprojects depended on the one actual file, not on generated files. I also removed the singleton class and replaced it with ordinary functions.