uga-rosa/translate.nvim

replace has some issues and still needs improvement

askfiy opened this issue · 4 comments

Some placeholders are deformed:

image

This is a problem from trans, which always inexplicably adds some extra spaces in the translation result.

If this space happens to split the placeholder, the final conversion will fail.

It might be better to remove the outer parentheses:

translate_shell = {
    ["="] = "{@E@}",
    ["#"] = "{@S@}",
    ["/"] = "{@C@}",
},

image

If you keep the default:

image

This problem is not just with translate_shell, google also adds some extra spaces.

Frankly, I don't think the first one is a practical problem, but I would like to address the translation of paths, as it is something that could well happen in actual use. Would using {@C@} be a complete solution?

This problem is not just with translate_shell, google also adds some extra spaces.

As for command/google, I think it can be translated without replace.

First of all, when I found this problem, I was thinking why this happened.

trans uses the Google API by default, which randomly inserts extra spaces in the translation result, so the {{@C@}} is split.

                ////////
                    │
                    ▼
                replace before
                    │
                    ▼
{{@C@}}{{@C@}}{{@C@}}{{@C@}}{{@C@}}{{@C@}}{{@C@}}{{@C@}}
                    │
                    ▼
    trans (the problem is upstream, random spaces are added)
                    │
                    ▼
{{@C@}}{{@C@}} {{@C@}}{{@C@}} {{@C@}}{ {@C@}}{{@C@}}{{@C@}}
                    │
                    ▼
                result after
                    │
                    ▼
// // / { {@C@}}//

To verify if this issue was caused by Google API randomly inserted spaces, I tried again using the plugin's default Google to try the translation.

//////////////////////
        │
        ▼
      google
        │
        ▼
////////////// ///////

Good job, randomly inserted spaces This question comes from Google API

Is there any way to solve it? Essentially no, because we're not sure where random spaces will be added.

The only thing that can be done is to reduce the length of the placeholder to make it simpler.

So {@C@} works better than {{@C@}}.

in conclusion:

  • {@C@} works better than {{@C@}}
  • This issue is caused by **randomly inserted spaces** in Google API (which is used internally by translate-shell)