Builditluc / wiki-tui

A simple and easy to use Wikipedia Text User Interface
https://wiki-tui.net/
MIT License
417 stars 14 forks source link

Add Language Selection #168

Closed Builditluc closed 1 year ago

Builditluc commented 1 year ago

Closes #165

Changes made:

Release Notes

You can now change the language on the fly either by using the new -l and --language cli arguments, or by pressing F2 in the tui and selecting a new language from the menu. This feature also includes several new configuration options, so be sure to check out the docs about them

Please also check the docs to learn about what breaking changes have occurred since 0.6.x

image

Language Switching Dialog

cshjsc commented 1 year ago

I see that the menu just contains four languages I know its hard to actually implement a list for all of them because well who will write such a thing. so we could add an option to the menu called select another language, and make a request to wikipedia https://meta.wikimedia.org/w/api.php?action=sitematrix&format=json&smtype=language&formatversion=2, this returns all the languages in a json structure like this one

 "66": {
      "code": "de",
      "name": "Deutsch",
      "site": [
        {
          "url": "https://de.wikipedia.org",
          "dbname": "dewiki",
          "code": "wiki",
          "sitename": "Wikipedia"
        },
        {
          "url": "https://de.wiktionary.org",
          "dbname": "dewiktionary",
          "code": "wiktionary",
          "sitename": "Wiktionary"
        },
        {
          "url": "https://de.wikibooks.org",
          "dbname": "dewikibooks",
          "code": "wikibooks",
          "sitename": "Wikibooks"
        },
        {
          "url": "https://de.wikinews.org",
          "dbname": "dewikinews",
          "code": "wikinews",
          "sitename": "Wikinews"
        },
        {
          "url": "https://de.wikiquote.org",
          "dbname": "dewikiquote",
          "code": "wikiquote",
          "sitename": "Wikiquote"
        },
        {
          "url": "https://de.wikisource.org",
          "dbname": "dewikisource",
          "code": "wikisource",
          "sitename": "Wikisource"
        },
        {
          "url": "https://de.wikiversity.org",
          "dbname": "dewikiversity",
          "code": "wikiversity",
          "sitename": "Wikiversity"
        },
        {
          "url": "https://de.wikivoyage.org",
          "dbname": "dewikivoyage",
          "code": "wikivoyage",
          "sitename": "Wikivoyage"
        }
      ],
      "dir": "ltr",
      "localname": "German"
    },

I could implement this if you want

Builditluc commented 1 year ago

That's cool, I didn't know this API call existed. It would be a more straightforward way of implementing all languages into the program, however, we still have to support changing the language via the configuration file, and requesting Wikimedia every time we start the program would slow down the start. I've created a macro in language.rs that simplifies the process of adding new languages, so yes, it's more tedious than making the request, but we still have an easy way of loading the configuration file.

If you know of a way to use the API call without it slowing down the startup, feel free to start working on it (I can also help with understanding the, a bit messy, codebase if you need any). Just let me know!

cshjsc commented 1 year ago

We could have a macro in another crate which generates and exposes an enum for the languages at compile time based on a file, or we could do that too in this project but I'm not sure if that would get compiled over and over again, we just need then to update the file if needed, that way we are not internet dependent. I can't come up right now with more ideas...

Builditluc commented 1 year ago

Okay, so you mean we have a file that gets loaded at compile time, containing all of the languages from the API request? I believe it'd be simpler if we stick with the enum because we have a concrete type for every language

cshjsc commented 1 year ago

I mean the enum is generated at compile time

Builditluc commented 1 year ago

I've looked into this for the last hour and found that we can do this by generating the enum in the build.rs file (build script). If you want you can implement this, just create a pull request against the language-switching branch (make sure to create your branch from the language-switching branch).

cshjsc commented 1 year ago

yes I'm already on it I'm creating a procedural macro with syn, I'm trying to parse the file and create the enum variants. I'll make the pull request when I'm done

Builditluc commented 1 year ago

Great! Thank you so much for your contributions! I'll work on making the popup a bit prettier (search, etc.)

cshjsc commented 1 year ago

I created a PR for it.

Builditluc commented 1 year ago

Because we may need to search over multiple lists of strings and this feature can be abstracted away into a single view, I've created the cursive-fuzzy-search-view repo, where I'll create the view for fuzzy-searching over a list of items. Feel free to contribute or make suggestions!

cshjsc commented 1 year ago

Sounds good, either that or adding a dependency like ripgrep and do it that way

Builditluc commented 1 year ago

Hey @cshjsc, sorry for the pause in development (I had a lot of things to do IRL), but language switching should mostly be implemented by now. A few quality-of-life features are still missing:

Please let me know if you want any other language-switching feature implemented or modified!

cshjsc commented 1 year ago

Hi, don't worry I've been busy too, well I could implement some of those features this or next week if you want... But if it works now, I would merge it as it is.

Builditluc commented 1 year ago

But if it works now, I would merge it as it is.

Yeah, you're right. I've implemented the -l argument and the display of the language in the search results, but I think anything other would be best packed into another feature.

If you have any other suggestions you want to be added for 0.7, just let me know! Otherwise, I'll start preparing the release