old_contents: import logging
  from collections import defaultdict
  from langid.langid import LanguageIdentifier, model
  # https://github.com/saffsd/langid.py
  
  from aleph.analyze.analyzer import Analyzer
  
  log = logging.getLogger(__name__)
  
  THRESHOLD = 0.9
  CUTOFF = 30
  
  
  class LanguageAnalyzer(Analyzer):
  
      @property
      def identifier(self):
          if not hasattr(LanguageAnalyzer, '_identifier'):
              LanguageAnalyzer._identifier = \
                  LanguageIdentifier.from_modelstring(model, norm_probs=True)
          return LanguageAnalyzer._identifier
  
      def prepare(self):
          self.languages = defaultdict(float)
  
      def on_text(self, text):
          if len(self.meta.languages) > 0:
              return
          if len(text.strip()) < CUTOFF:
              return
          lang, score = self.identifier.classify(text)
          if score > THRESHOLD:
              self.languages[lang] += score * len(text)
  
      def finalize(self):
          if len(self.meta.languages) > 0:
              return
          if not len(self.languages):
              return
  
          languages = sorted(self.languages.items(), key=lambda (l, c): c,
                             reverse=True)
          self.meta.add_language(languages[0][0])
          log.info("Classified languages in %r: %r", self.document,
                   languages[:10])
  
new_contents: import logging
  from collections import defaultdict
  from langid.langid import LanguageIdentifier, model
  # https://github.com/saffsd/langid.py
  
  from aleph.analyze.analyzer import Analyzer
  
  log = logging.getLogger(__name__)
  
  THRESHOLD = 0.9
  CUTOFF = 30
  
  
  class LanguageAnalyzer(Analyzer):
  
      @property
      def identifier(self):
          if not hasattr(LanguageAnalyzer, '_identifier'):
              LanguageAnalyzer._identifier = \
                  LanguageIdentifier.from_modelstring(model, norm_probs=True)
          return LanguageAnalyzer._identifier
  
      def prepare(self):
          self.languages = defaultdict(float)
  
      def on_text(self, text):
          if len(self.meta.languages) > 0:
              return
          if len(text.strip()) < CUTOFF:
              return
          lang, score = self.identifier.classify(text)
          if score > THRESHOLD:
              self.languages[lang] += score * len(text)
  
      def finalize(self):
          if len(self.meta.languages) > 0:
              return
          if not len(self.languages):
              return
  
          for code, score in self.languages.items():
              self.meta.add_language(code)
          log.info("Classified languages in %r: %r", self.document,
                   self.meta.languages.keys())
  
subject: Allow language detector to recognise multiple languages, fixes #54.