RupertAvery / DiffusionToolkit

Metadata-indexer and Viewer for AI-generated images
MIT License
743 stars 46 forks source link

[Enhancement] Localization Support #121

Open NaokiSato102 opened 1 year ago

NaokiSato102 commented 1 year ago

Is your feature request related to a problem? Please describe.
There is no mechanism in the UI to accommodate multilingual support, making it impossible to provide translation files and perform translations.

Describe the solution you'd like
I would like you to implement internationalization (i18n).
It would be beneficial if the translations could be stored and accessed in an editable text format, such as a key-value store like JSON.
It is preferable to avoid using binary files because they are more difficult to handle.

RupertAvery commented 1 year ago

Do you have a specific format that you would use to manage localized text? Is there some standard? Do you want DiffusionToolkit to be able to load them in from raw text?

I started using the standard Resource.resx files, and thought of having some tool to dump them to JSON and import them back to resx, but this won't help for translators who wish to be able to reload them and see how they look.

RupertAvery commented 1 year ago

So I'm now using a library to help with localization, and it's flexible enough to use Resx or other formats.

I'm currently using Resx as all that is needed is to have a key to identify the string, so a JSON file would just have to use the same key.

Would you need a build of Diffusion Toolkit that has support for i18n ready, or can you work with the source code and compile it?

The question being, I am currently moving the strings into the resource file and replacing with key values. So you would have to wait for me to completely move them to Resx and then build a JSON translation provider before you could get to work on translations, but if you could work with the code directly and map some strings, it would help a lot.

Of course, there's the problem of dividing up the text so we don't step on each other's feet.

Anyway, I'll just continue this for now.

NaokiSato102 commented 1 year ago

As modifying the structural aspects requires code comprehension, I'll leave that to you. I would like to participate in preparing the JSON key-value pairs when they are ready.

RupertAvery commented 8 months ago

Are you able to work with git and build on your machine? I have an initial implementation. I'm in the process of moving the hardcoded text into localized text. The localizations will be stored in a JSON file but in a simple dictionary (key: value) format.

Here is a sample of the current version:

{
  "Menu.File": "_File",
  "Menu.File.Close": "_Close",
  "Menu.Edit": "_Edit",
  "Menu.Edit.Settings": "_Settings",
  "Menu.Edit.EmptyRecycleBin": "_Empty recycle bin",
  "Menu.Edit.RebuildMetadata": "_Rebuild metadata",
  "Menu.Edit.ReloadModels": "Reload _models",
  "Menu.Edit.DownloadCivitaiModels": "Download _Civitai models",
  "Menu.View": "_View",
  "Menu.View.Filter": "_Filter",
  "Menu.View.Refresh": "_Refresh",
  "Menu.View.AutoRefresh": "_Auto Refresh",
  "Menu.View.Thumbnails": "_Thumbnails",
  "Menu.View.BlurNSFW": "Blur _NSFW",
  "Menu.View.HideNSFWFromResults": "_Hide NSFW from Results",
  "Menu.View.FitToPreview": "_Fit to Preview",
  "Menu.View.TogglePreview": "Show/Hide Preview",
  "Menu.View.PopoutPreview": "Popout Preview",
  "Menu.Albums": "_Albums",
  "Menu.Albums.AlbumPane": "Album Pane",
  "Menu.Albums.Sort": "_Sort",
  "Menu.Tools": "_Tools",
  "Menu.Tools.SearchResults": "_Search results",
  "Menu.Tools.SearchResults.AddAllToAlbum": "_Add all search results to Album",
  "Menu.Tools.SearchResults.MarkAllForDeletion": "_Mark all search results for Deletion",
  "Menu.Tools.SearchResults.UnmarkAllForDeletion": "_Unmark all search results for Deletion",
  "Menu.Tools.SearchResults.RemoveMatching": "_Remove all query results from the database",
  "Menu.Tools.AutoTagNSFW": "_Auto tag NSFW",
  "Menu.Tools.Folders": "_Folders",
  "Menu.Tools.Folders.": "_Folders",
  "Menu.Tools.Folders.FixMissingImages": "_Fix missing images",
  "Menu.Tools.Folders.RemoveExcludedImages": "_Remove excluded images",
  "Menu.Tools.Folders.CleanRemovedFolders": "_Clean removed folders",
  "Menu.Help": "_Help",
  "Menu.Help.About": "About",
  "Menu.Help.GettingStarted": "Getting Started",
  "Menu.Help.CheckForUpdates": "_Check for updates",
  "Common.Buttons.OK": "OK",
  "Common.Buttons.Cancel": "Cancel",
  "Common.Buttons.Yes": "Yes",
  "Common.Buttons.No": "No",
  "Common.Buttons.Browse": "Browse",
  "Common.Buttons.Apply": "Apply",
  "Common.Buttons.Close": "Close",
  "Common.MessageBox.ConfirmCancelOperation": "Are you sure you want to cancel the operation?",
  "Common.MessageBox.OperationCancelled": "The operation was cancelled.",
  ...
}

It would be ideal if you could work on a branch and check in the files manually. If not, you can work with this version:

Diffusion.Toolkit.Localization.zip

Currently, the main menu and settings and messagebox buttons have been localized.

A new setting has been added in Settings > Themes > Language

To create a new localization, create a copy of Localization\default.json and rename it to the culture/lanuage code, e.g. de-DE.json. Open Localization\languages.json and add an entry for the language e.g.

{
   "German": "de-DE"
}

This will make the language show in the Settings > Themes > Language drop down.

The Default settings should use the current culture of your system. Everything should default to the english text that is embedded in the application.

RupertAvery commented 8 months ago

Latest commits now have localization support, as well as ChatGPT-sourced translations.

Please see if the Japanese translation is accurate.

Diffusion.Toolkit.v1.6 beta.zip

ありがとうございます!

NaokiSato102 commented 8 months ago

Sorry for not being able to help much due to being busy. I'll check on it.

NaokiSato102 commented 8 months ago

I have modified some of the existing Japanese translations, particularly for longer texts. I've rearranged the settings descriptions into a format of '1. What you should do 2. What becomes possible by doing so.' I've clarified translations that were hard to understand due to the use of subjects, qualifiers, and words derived from opposites. The order of 1 and 2 could be reversed, but this is my preference.

There were parts that were not translated, so I have illustrated those sections and written a dictionary for them. Please feel free to use it.

"設定画面":{ "画像":{ "open images using" : "画像閲覧方法", "Built-in viewer":"ビルドインビューワ", "Open in fullscreen":"フルスクリーンで表示", "System default":"Windows既定方法", "Custom":"カスタム", "Argments":"起動引数", "Scan for new images on startup":"起動時に新たな画像をスキャン" } "NSFW":{ "NFSW Tags: (one token on each line)":"NSFWタグ (1トークンにつき1行)" }

}

Suggestion: Could 'NFSW Tags: (one token on each line)' be a typographical error for 'NSFW Tags: (one token on each line)'? 1

2

languages.json

ja-JP.json

NaokiSato102 commented 8 months ago

miss uploaded. ja-JP.json