Skip to content

Add I18n support example by use rust-i18n#3

Draft
huacnlee wants to merge 3 commits into
mainfrom
i18n
Draft

Add I18n support example by use rust-i18n#3
huacnlee wants to merge 3 commits into
mainfrom
i18n

Conversation

@huacnlee

@huacnlee huacnlee commented Jun 1, 2024

Copy link
Copy Markdown
Owner

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
@neodev27

Copy link
Copy Markdown

Will anyone check this out again? I want to use Zed in my language and I'm sure there are people waiting to translate Zed to their language...
PLEASE!

huacnlee pushed a commit that referenced this pull request Apr 14, 2026
data_table: Replace column width builder API with `ColumnWidthConfig`
enum

This PR consolidates the data table width configuration API from three
separate builder methods (`.column_widths()`, `.resizable_columns()`,
`.width()`) into a single `.width_config(ColumnWidthConfig)` call. This
makes invalid state combinations unrepresentable and clarifies the two
distinct width management modes.

**What changed:**

- Introduces `ColumnWidthConfig` enum with two variants:
  - `Static`: Fixed column widths, no resize handles
- `Redistributable`: Drag-to-resize columns that redistribute space
within a fixed table width
- Introduces `TableResizeBehavior` enum (`None`, `Resizable`,
`MinSize(f32)`) for per-column resize policy
- Renames `TableColumnWidths` → `RedistributableColumnsState` to better
reflect its purpose
- Extracts all width management logic into a new `width_management.rs`
module
- Updates all callers: `csv_preview`, `git_graph`, `keymap_editor`,
`edit_prediction_context_view`

```rust
pub enum ColumnWidthConfig {
    /// Static column widths (no resize handles).
    Static {
        widths: StaticColumnWidths,
        /// Controls widths of the whole table.
        table_width: Option<DefiniteLength>,
    },
    /// Redistributable columns — dragging redistributes the fixed available space
    /// among columns without changing the overall table width.
    Redistributable {
        entity: Entity<RedistributableColumnsState>,
        table_width: Option<DefiniteLength>,
    },
}
```

**Why:**

The old API allowed callers to combine methods incorrectly. The new
enum-based design enforces correct usage at compile time and provides a
clearer path for adding independently resizable columns in PR #3.

**Context:**

This is part 2 of a 3-PR series improving data table column width
handling:
1. [zed-industries#51059](zed-industries#51059) - Extract
modules into separate files (mechanical change)
2. **This PR**: Introduce width config enum for redistributable column
widths (API rework)
3. Implement independently resizable column widths (new feature)

The series builds on previously merged infrastructure:
- [zed-industries#46341](zed-industries#46341) - Data
table dynamic column support
- [zed-industries#46190](zed-industries#46190) - Variable
row height mode for data tables

Primary beneficiary: CSV preview feature
([zed-industries#48207](zed-industries#48207))


### Anthony's note

This PR also fixes the table dividers being a couple pixels off, and the
csv preview from having double line rendering for a single column in
some cases.

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [ ] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- N/A

---------

Co-authored-by: Anthony Eid <anthony@zed.dev>
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.

2 participants