www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Dynamically import() files

reply Andre Pany <andre s-e-a-p.de> writes:
Hi,

I have a folder "i18n" which contains message bundle files. For 
now it contains only the message bundle file written by the 
developer: "messagebundle.properties".

During the translation process additional message bundle files 
will be added to github:
messagebundle_en.properties
messagebundle_de.properties
...
Changing the github content will automatically triggering the 
compilation process.
My wish is, that every time a new message bundle file is added, 
these file is automatically included into the compilation process.


I doubt, but is there a possibility to check during compile time 
which files exists in the
i18n folder and import() these files?

I see currently only 1 chance: Create a list of all possible 
language code (max 7) and check whether the import works via 
__traits(compiles,...).

Something like:
alias languages = TypeTuple!("en", "de");
static foreach(lang; languages)
{
...
}

Kind regards
André
Oct 23 2017
next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
Don't be afraid to write a small script that is run before a build to 
generate a list of files which than can be imported.
Oct 23 2017
prev sibling parent reply Igor <stojkovic.igor gmail.com> writes:
On Monday, 23 October 2017 at 12:15:17 UTC, Andre Pany wrote:
 Hi,

 I have a folder "i18n" which contains message bundle files. For 
 now it contains only the message bundle file written by the 
 developer: "messagebundle.properties".

 [...]
Can't you just create all the files that you expect to have and leave them empty and then you import them all and process them differently if there is no content?
Oct 23 2017
parent Andre Pany <andre s-e-a-p.de> writes:
On Monday, 23 October 2017 at 20:13:20 UTC, Igor wrote:
 On Monday, 23 October 2017 at 12:15:17 UTC, Andre Pany wrote:
 Hi,

 I have a folder "i18n" which contains message bundle files. 
 For now it contains only the message bundle file written by 
 the developer: "messagebundle.properties".

 [...]
Can't you just create all the files that you expect to have and leave them empty and then you import them all and process them differently if there is no content?
Thanks for the hints. I have some concerns creating the files upfront, because the files should only be created by other colleagues in an official translation process. I will check whether I can determine the files via script as proposed by Rikki. Kind regards André
Oct 23 2017