patrickschur / language-detection

A language detection library for PHP. Detects the language from a given text string.
MIT License
806 stars 83 forks source link

Create langLibrary form different directories #24

Open IgorFrancais opened 5 years ago

IgorFrancais commented 5 years ago

Hello,

Now, when we create a library, we can use following ways:

  1. new Language() - following directory will be used (by default): DIR . '/../../resources//.json';

  2. We use other .json-files (take as an example, en language): 2.1 Create at any place folder $dirname=LanguageDetection/en/. 2.2 Put there your own text file: en.txt. 2.3 Train library:

         $t = new Trainer();
         $t->learn($dirname);

    2.4 Then use newly created/updated .json-file: LanguageDetection/en/en.json by:

new Language([], $dirname)

So, if we want to use default lang file, we should:

  1. Copy already existing en.txt to our newly created folder.
  2. Add our text to existing
  3. Train library.
  4. Use newly created/updated en.json

Request:

Not to copy-paste, it would be good have a possibility to use already existing en.json and newly created together, something like: new Language([], $dirname, $useDefaultFile = true):

patrickschur commented 5 years ago

Hello,

if I understand you correctly, you just want a simple merge function, right? That shouldn't be hard to implement. :)

IgorFrancais commented 5 years ago

Yes:) Something like

  1. Use default directory only or
  2. To use 2 directories with .json-files together: default `DIR . '/../../resources//*.json' `

and other, custom user's directory :)

patrickschur commented 4 years ago

Sorry for waiting so long... It's not as easy as I thought. I've stumpled across some issues here. When merging both directories (default and user directory), we also have to merge the language files. But we can't just merge the language files, because they are pre-sorted and merging would destroy the order.