tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
83.92k stars 2.52k forks source link

[feat] How to switch app language dynamically #8281

Open ayangweb opened 11 months ago

ayangweb commented 11 months ago

Describe the problem

image

I want to change the default language of the app and then dynamically switch the language of the app, how should I do it?

Describe the solution you'd like

I hope this solves my confusion!

Alternatives considered

No response

Additional context

No response

makao007 commented 10 months ago

get user-agent info inside the javascript code ?

drernie commented 10 months ago

What precisely do you mean by "switch the language"? Is the issue that you initially told create-tauri-app that you wanted to use JavaScript for the front-end, but now want to use Rust (or vice versa)?

If so, it seems like you'd be better of recreating the project from scratch, then copy over the few files that didn't depend on that language. Or am I missing something?

ayangweb commented 10 months ago

What precisely do you mean by "switch the language"? Is the issue that you initially told create-tauri-app that you wanted to use JavaScript for the front-end, but now want to use Rust (or vice versa)?

If so, it seems like you'd be better of recreating the project from scratch, then copy over the few files that didn't depend on that language. Or am I missing something?

I have a button that switches between Chinese and English, and the content on the page can be switched normally, but how can I switch the language of the window at the same time?

Chinese:

image

English:

image

Currently I can only write the following information in info.plist before I can achieve the above effect, and it is not possible to switch it at any time with a button, so how can I achieve it in other ways?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>CFBundleDevelopmentRegion</key>
  <string>Chinese</string>
</dict>
</plist>
ayangweb commented 4 months ago

get user-agent info inside the javascript code ?

I'm sorry to get back to you so late, have you ever realized this? Can you share? Thank you!

nyssance commented 1 week ago

What precisely do you mean by "switch the language"? Is the issue that you initially told create-tauri-app that you wanted to use JavaScript for the front-end, but now want to use Rust (or vice versa)? If so, it seems like you'd be better of recreating the project from scratch, then copy over the few files that didn't depend on that language. Or am I missing something?

I have a button that switches between Chinese and English, and the content on the page can be switched normally, but how can I switch the language of the window at the same time?

Chinese: image

English: image

Currently I can only write the following information in info.plist before I can achieve the above effect, and it is not possible to switch it at any time with a button, so how can I achieve it in other ways?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>CFBundleDevelopmentRegion</key>
  <string>Chinese</string>
</dict>
</plist>

The i18n for native iOS/macOS development,Just config CFBundleDevelopmentRegion like this, I'm not test it in tauri, but I think it will work.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
</dict>
</plist>

BTW: The default name is Info.plist, not info.plist, if not work, try to change filename.