maxim-saplin / dikt

Off-line dictionary with simplistic UI. Optimized for one-hand on with mobile phones. Cross-platform, tailored desktop as well
MIT License
34 stars 5 forks source link

Cannot open one json dictionary #3

Open yumeo-ch opened 1 year ago

yumeo-ch commented 1 year ago

Hello, Thank you for the job first of all. There is a dictionary I want to open : https://github.com/VahidN/EnglishToPersianDictionaries/blob/master/Dictionaries/subtitles/B.json But it doesn't work with dikt, how can I open this JSON file? Pyglossary doesn't read json files and I couldn't find another app capable of doing so.

ilius commented 1 year ago

That's a different json format. Can you open a discussion here? https://github.com/ilius/pyglossary/discussions

maxim-saplin commented 1 year ago

Hi, thanks for the interest. The problem is due to DIKT expecting a different structure of JSON. In your case you have this:

{
  "Group": "B",
  "Entries": 21736,
  "Words": [
    {
      "EnglishWord": "b  cardinal richelieu",
      "Meanings": [
        "ب کاردینال ریچلیو"
      ]
    },
    {
      "EnglishWord": "b  franklin roosevelt",
      "Meanings": [
        "ب فرانکلین روزولت"
      ]
    }
  ]

while the app expects a simpler structure with keys being words and values being translations, e.g.:

 {
  "b  cardinal richelieu": "ب کاردینال ریچلیو",
  "b  Franklin roosevelt": "ب فرانکلین روزولت"
}

Here's an example JS to transform the structure you shared to JSON that is supported by DIKT:

function transformJson(input) {
  const output = {};

  input.Words.forEach(word => {
    const englishWord = word.EnglishWord;
    const meanings = word.Meanings.join('\n');
    output[englishWord] = meanings;
  });

  return output;
}

const inputJson = {
  "Group": "B",
  "Entries": 21736,
  "Words": [
    {
      "EnglishWord": "b  cardinal richelieu",
      "Meanings": [
        "ب کاردینال ریچلیو"
      ]
    },
    {
      "EnglishWord": "b  franklin roosevelt",
      "Meanings": [
        "ب فرانکلین روزولت"
      ]
    }
  ]
};

const transformedJson = transformJson(inputJson);
console.log(transformedJson);
yumeo-ch commented 1 year ago

Hey, thank you for great explanation, but doing so doesn't resolve the issue, I still have error when importing the JSON file with your structure (I even have error when I copy paste your example code in a bank file and save it as test.json).

maxim-saplin commented 1 year ago

Please share the file with the supported structure for me to look at

yumeo-ch commented 1 year ago

Please share the file with the supported structure for me to look at

https://1fichier.com/?ckrc0f8zbn8r6ywhfn6b

Sure, here you are

maxim-saplin commented 1 year ago

Apparently the file you provided is not JSON (but rather some piece of JS) and can not work in principle, no matter the structure which is supported by the app.

image
yumeo-ch commented 1 year ago

I see, do you know any solution or any way to "convrrt" them ? I guess it shouldn't be that hard. I would open a discussion on pyglossary as well.