-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make better use of i18n #20096
Make better use of i18n #20096
Conversation
I think it's on the correct direction for the i18n refactoring. The only question in my mind is: is the perfect hash map necessary? If the simple map can still save the memory and works fine, I would prefer to use a simple map (like |
So, I'd preferred the perfect hash as it was made for these kind of situations, need fast query and the keys are known before-hand. Thereby there was no really good quality perfect hash library(so that's why I crafted one and included in the PR). I've pushed a commit(d498472) that utilized the same concept of the language offset and then instead use golang's Map feature. The memory is bit more on the heap(it says 10Mb) but the overall memory usage still seems to be around the same levels of what the previous implementation had. 6bfa1ba actually is the one that moves back the original data structure that is optimized for memory. |
- Uses less memory by creating for each language a map.
L-G-T-M (except CI failure is related) And, could the |
That issue once again... |
|
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.
I think, I got the gist of what you're doing.
If it works, LGTM.
- Separate dev and production locale stores. - Allow for live-reloading in dev mode. Co-authored-by: zeripath <[email protected]>
Pushed commits to separate dev and production localestores(so it's easier to implement live-reloading etc.). Provided by @zeripath |
I think some code can be simplified, will try on it later. |
Even more refactors 😄 I will mark this PR for 1.19 already |
I believe 1.18 is fine ( |
I proposed a PR about my idea. Gusted#5 Major benefits:
|
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.
(approve, although I also made some changes, open for suggestions)
* giteaofficial/main: Add spacing between the properties of the key (go-gitea#20145) Remove U2F support (go-gitea#20141) Make better use of i18n (go-gitea#20096)
- Currently we're using the `i18n` variable naming for the `locale` struct. This contains locale's specific information and cannot be used for general i18n purpose, therefore refactoring it to `locale` makes more sense. - Ref: go-gitea#20096 (comment)
* Refactor `i18n` to `locale` - Currently we're using the `i18n` variable naming for the `locale` struct. This contains locale's specific information and cannot be used for general i18n purpose, therefore refactoring it to `locale` makes more sense. - Ref: #20096 (comment) * Update routers/install/install.go
* Prototyping * Start work on creating offsets * Modify tests * Start prototyping with actual MPH * Twiddle around * Twiddle around comments * Convert templates * Fix external languages * Fix latest translation * Fix some test * Tidy up code * Use simple map * go mod tidy * Move back to data structure - Uses less memory by creating for each language a map. * Apply suggestions from code review Co-authored-by: delvh <[email protected]> * Add some comments * Fix tests * Try to fix tests * Use en-US as defacto fallback * Use correct slices * refactor (go-gitea#4) * Remove TryTr, add log for missing translation key * Refactor i18n - Separate dev and production locale stores. - Allow for live-reloading in dev mode. Co-authored-by: zeripath <[email protected]> * Fix live-reloading & check for errors * Make linter happy * live-reload with periodic check (go-gitea#5) * Fix tests Co-authored-by: delvh <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: zeripath <[email protected]>
* Refactor `i18n` to `locale` - Currently we're using the `i18n` variable naming for the `locale` struct. This contains locale's specific information and cannot be used for general i18n purpose, therefore refactoring it to `locale` makes more sense. - Ref: go-gitea#20096 (comment) * Update routers/install/install.go
As we add more translations and languages, this strategy won't scale and has become visible and measurable in memory utilization. All parsed ini currently uses about 20-30Mb of memory, which is nothing on modern computers. Every bit counts when running Gitea on low-powered devices like Raspberry Pis and Android phones. This PR fixes that by using a new data structure that don't require more memory than is necessary and is scalable for the future.
translation key -> index
and for each locale a mapsindex -> translation value
.index -> translation value
, so you don't have to do another map lookup to get the locale struct.Before:
25Mb to initialize the locales(After Go's GC)
After:
7Mb to initialize the locales(After Go's GC)
As usual, goodluck reviewing this piece of beauty and mess.