MagicMirror icon indicating copy to clipboard operation
MagicMirror copied to clipboard

module translations getTranslations() enhancement

Open sdetweil opened this issue 2 years ago • 14 comments

for module translations, is there any mechanism to select all files in the translations folder (without enumerating them in the getTranslations() call?

like "translations/*" means load them all.

that would make it easy for someone to add a new one, and NOT have to change the code...

sdetweil avatar Jun 01 '23 02:06 sdetweil

yes it would be easier Reading of the translations directory of the module

But... it will be more complicated to determine the default language file to use (actually the first one of getTranslations)

bugsounet avatar Jun 10 '23 14:06 bugsounet

But... it will be more complicated to determine the default language file to use (actually the first one of getTranslations)

So, in case of https://github.com/MichMich/MagicMirror/blob/abe5c08a52ffee6b37c30c1f3160e130f0e966a2/modules/default/alert/alert.js#L28 it would be "bulgaria" which is the default language?

rejas avatar Jun 10 '23 20:06 rejas

but we have the language setting in config.js

sdetweil avatar Jun 10 '23 20:06 sdetweil

sure, we know that ;)

sdetweil Idea is:

getTranslations() { 
  return {
    files: "translations/*"
  }
}

For read all files automaticaly files of translations folder of the module Maybe another function is needed

it's +/- your idea @sdetweil ? it's that?

bugsounet avatar Jun 10 '23 20:06 bugsounet

but we have the language setting in config.js

but if json file of this translatated part don't exist ?

bugsounet avatar Jun 10 '23 20:06 bugsounet

read all translations files available..

this would help a novice user create a new file , put it in folder, and it works.. doesn't have to edit source (which breaks updates)

sdetweil avatar Jun 10 '23 20:06 sdetweil

what happens now?

sdetweil avatar Jun 10 '23 20:06 sdetweil

read all translations files available..

this would help a novice user create a new file , put it in folder, and it works.. doesn't have to edit source (which breaks updates)

it's ok, we are talking about the same feature ;)

bugsounet avatar Jun 10 '23 20:06 bugsounet

I had thought this:

  • define a directory with translations
  • create a json file with a new specificity / syntax
{
    lang: [language tag]
    default: [boolean]
    translations: [object Translations]
}
  • Read automatically this directory and make translations job
  • use default lang to apply for the module (fallback)
  • if getTranslations() used, ignore this rule

Yes i know, it's a shame not to have thought of this from the start.

bugsounet avatar Jun 10 '23 20:06 bugsounet

BUT... that file would belong to the module and locally changed would break updates (even to include the new file)

sdetweil avatar Jun 10 '23 20:06 sdetweil

yes and no, because there is une files by language too and can be added automaticaly

but yes, if you modify one of lang file, it's break update too but a new language file is added automaticaly without modify main core

bugsounet avatar Jun 10 '23 20:06 bugsounet

but yes, if you modify one of lang file, it's break update too

trying to add function that helps and does not hurt the user..

sdetweil avatar Jun 10 '23 21:06 sdetweil

I don't know if we can request a reloading of the translation files

otherwise my idea would be to go through the node helper with node fs

  • read the contents of the directory (only json files)
  • return the result.
  • reload the transcription files with the result option

Note: I did not check if node js is available in a module core (I don't think so)

bugsounet avatar Jun 11 '23 21:06 bugsounet

why reloading? on startup. read new list of files

sdetweil avatar Jun 11 '23 23:06 sdetweil