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 I18n support example by use rust-i18n #3

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Add I18n support example by use rust-i18n #3

wants to merge 3 commits into from

Conversation

huacnlee
Copy link
Owner

@huacnlee huacnlee commented Jun 1, 2024

Introduce

I made this PR as an example to describe how we use rust-i18n for Zed.

Use the rust-i18n crate (This is implemented by myself) to add I18n support to Zed.

Tasks

  • Add i18n crate into zed workspace, to manage locales load, and export rust_i18n method again.
    • Then other crates only use i18n::t macro to get translate text.
  • Add locale settings to set the UI language.
  • Support load locales from Zed workdir, for support to install other locales at the Zed runtime from Zed server (like an extension).
  • Extract main UI text into locale files and replace to use t! macro.

Screenshot

image

Ref:

@huacnlee huacnlee changed the title Add I18n support Draft I18n support Jun 1, 2024
@huacnlee huacnlee changed the title Draft I18n support Draft I18n support example by use rust-i18n Jun 1, 2024
huacnlee added a commit to longbridge/rust-i18n that referenced this pull request Jun 3, 2024
Based on real world uses: huacnlee/zed#3

Update example to embed I18n in single crate, and share it in entire
workspace.
@huacnlee huacnlee changed the base branch from main to zip-unarchive-support-backup July 19, 2024 16:18
@huacnlee huacnlee changed the base branch from zip-unarchive-support-backup to main July 19, 2024 16:18
huacnlee pushed a commit that referenced this pull request Nov 7, 2024
Closes zed-industries#17388

Release Notes:

- N/A

We are using gpui to build a project, and we want to render SVGs with
the `<text>` tag. We use `resvg` and `usvg` with the same version as
gpui, like `0.41.0`. However, when we enable the feature `text`, we get
an error from `usvg`.

```shell
error[E0061]: this function takes 3 arguments but 2 arguments were supplied
  --> /Users/madcodelife/.cargo/git/checkouts/zed-23e65a6dff445450/e681a4b/crates/gpui/src/svg_renderer.rs:49:20
   |
49 |         let tree = usvg::Tree::from_data(bytes, &usvg::Options::default())?;
   |                    ^^^^^^^^^^^^^^^^^^^^^---------------------------------- argument #3 of type `&Database` is missing
   |
```

This error occurs because when the `text` feature is enabled, the
`form_data` function needs an extra argument, `fontdb`.
[The code is
here](https://github.com/linebender/resvg/blob/fb7e28513f561ed847acbf4a6fb8b743474837a0/crates/usvg/src/parser/mod.rs#L98).

They changed the API in version
[`0.42.0`](https://github.com/linebender/resvg/blob/b1d06e9463a3b089fbd70e7c38aebbfc811311ff/crates/usvg/src/parser/mod.rs#L98).

So, I updated the versions to the latest (0.44.0).

This is our demo:

## Before:
<img width="620" alt="image"
src="https://github.com/user-attachments/assets/7c71f8b1-e5fe-4e60-8f21-bb3bd9924e03">

## After:
<img width="620" alt="image"
src="https://github.com/user-attachments/assets/4b0a0602-928f-4017-b5df-859eeb5f6b4a">
@huacnlee huacnlee changed the title Draft I18n support example by use rust-i18n Add I18n support example by use rust-i18n Nov 26, 2024
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

Successfully merging this pull request may close these issues.

1 participant