Exemple #1
0
def update_translation_changelist_for_undelete():
  """Create all the required translations if not defined"""
  from application import db
  from models.translation import Translation
  
  itemDict = {
    'changes_v2.1.0.2': {
      'en': """<ul>
          <li>Added the un-delete feature</li>
        </ul>""",
      'ru': """<ul>
          <li>Добавлена возможность отмены удаления</li>
        </ul>""",
      'uk': """<ul>
          <li>Додано можливість скасувати видалення</li>
        </ul>""",
    }
  }
  
  for name, itemDictValue in itemDict.items():
    for language, value in itemDictValue.items():
      translation = Translation.query.filter_by(name=name, language=language).first()
      if not translation:
        translation = Translation()
        translation.language = language
        translation.name = name
        translation.value = value
        translation.save()
      else:
        translation.value = value
        translation.save()
Exemple #2
0
def update_translation_data_add_about_page_translations():
  """Create all the required translations if not defined"""
  from application import db
  from models.translation import Translation
  
  itemDict = {
    'about service': {
      'en': 'About T<sup>3</sup>',
      'ru': 'О сервисе T<sup>3</sup>',
      'uk': 'Про сервіс T<sup>3</sup>'
    },
    'and others': {
      'en': 'and many others',
      'ru': 'и многим другим',
      'uk': 'та багатьом іншим'
    },
    'changes_v2.1.0.1': {
      'en': """<ul>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li>Added the "About" page</li>
        </ul>""",
      'ru': '',
      'uk': ''
    },
    'common:changes': {
      'en': 'Changes',
      'ru': 'Изменения',
      'uk': 'Що нового'
    },
    'common:version_short': {
      'en': 'ver',
      'ru': 'ver',
      'uk': 'ver'
    },
    'thanks to': {
      'en': 'Thanks to',
      'ru': 'Отдельная благодарность',
      'uk': 'Дуже дякую'
    }
  }
  
  for name, itemDictValue in itemDict.items():
    for language, value in itemDictValue.items():
      translation = Translation.query.filter_by(name=name, language=language).first()
      if not translation:
        translation = Translation()
        translation.language = language
        translation.name = name
        translation.value = value
        translation.save()
      else:
        translation.value = value
        translation.save()
Exemple #3
0
def update_floats_separator():
  """Create all the required translations if not defined"""
  from application import db
  from models.translation import Translation

  itemDict = {
    'changes_v2.1.0.3': {
      'en': """<ul>
          <li>Added a preference: decimal separator for the floating-point numbers</li>
        </ul>""",
      'ru': """<ul>
          <li>Добавлена настройка: разделитель для дробной части в числах с плавающей точкой</li>
        </ul>""",
      'uk': """<ul>
          <li>Додано налаштування: роздільник для дробової частини в числах з плаваючою точкою</li>
        </ul>""",
    },
    'floats format': {
      'en': 'Decimal Separator',
      'ru': 'Разделитель в дробях',
      'uk': 'Роздільник в дробових числах'
    },
    'comma': {
      'en': 'Comma',
      'ru': 'Запятая',
      'uk': 'Кома'
    },
    'dot': {
      'en': 'Dot',
      'ru': 'Точка',
      'uk': 'Крапка'
    }
  }

  for name, itemDictValue in itemDict.items():
    for language, value in itemDictValue.items():
      translation = Translation.query.filter_by(name=name, language=language).first()
      if not translation:
        translation = Translation()
        translation.language = language
        translation.name = name
        translation.value = value
        translation.save()
      else:
        translation.value = value
        translation.save()
Exemple #4
0
def translate():
    pool = mp.Pool(mp.cpu_count())
    basename = str(int(time.time()))
    current_time = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
    f = request.files['file']
    filepath = os.path.join(
        app.config['UPLOAD_FOLDER'], basename + '.pdf')
    translationProcess = TranslationProcess(
        status=STATUS_PROCESSING, name=f.filename, created_on=current_time, basename=basename)
    translationProcess.save()
    f.save(filepath)
    pool.apply_async(converttoimage, args=(
        filepath, app.config['UPLOAD_FOLDER'], basename, '_hin'), callback=capturetext)
    pool.close()
    pool.join()
    filtertext(app.config['UPLOAD_FOLDER'] + '/' + basename + '_hin.txt',
               app.config['UPLOAD_FOLDER'] + '/' + basename + '_hin_filtered.txt')
    processenglish(app.config['UPLOAD_FOLDER'] +
                   '/' + basename + '_hin_filtered.txt')
    translatewithanuvadaeng(app.config['UPLOAD_FOLDER'] +
                            '/' + basename + '_hin_filtered.txt', app.config['UPLOAD_FOLDER'] +
                            '/' + basename + '_eng_tran.txt')
    f_eng = open(app.config['UPLOAD_FOLDER'] + '/' +
                 basename + '_eng_tran.txt', 'r')
    english_res = []
    hindi_res = []
    for f in f_eng:
        english_res.append(f)
    f_eng.close()
    f_hin = open(app.config['UPLOAD_FOLDER'] + '/' +
                 basename + '_hin_filtered.txt', 'r')
    for f in f_hin:
        hindi_res.append(f)
    f_hin.close()
    data = {'hindi': hindi_res, 'english': english_res}
    translations = []
    for i in range(0, len(hindi_res)):
        translation = Translation(basename=str(
            basename), source=hindi_res[i], target=english_res[i])
        translations.append(translation)
    Translation.objects.insert(translations)
    for f in glob.glob(app.config['UPLOAD_FOLDER'] + '/' + basename + '*'):
        os.remove(f)
    res = CustomResponse(Status.SUCCESS.value, data)
    translationProcess = TranslationProcess.objects(basename=basename)
    translationProcess.update(set__status=STATUS_PROCESSED)
    return res.getres()
Exemple #5
0
def install_translation_data():
  """Create all the required translations if not defined"""
  from application import db
  from models.translation import Translation
  
  import csv
  csvFile = open('data/t3.csv', 'rb')
  csvData = csv.reader(csvFile, delimiter=',', quotechar='"')
  csvHeaderSkipped = False
  for item in csvData:
    if not csvHeaderSkipped:
      csvHeaderSkipped = True
      continue
    
    if not len(item):
      continue
    
    name = item[0]
    valueDict = {
      'en': (len(item)>1 and str(item[1]) or ''),
      'ru': (len(item)>2 and str(item[2]) or ''),
      'uk': (len(item)>3 and str(item[3]) or '')
    }
    
    for language, value in valueDict.items():
      
      translation = Translation.query.filter_by(language=language, name=name).first()
      if not translation:
        translation = Translation()
        translation.language = language
        translation.name = name
        translation.value = value
        translation.save()
      else:
        translation.value = value
        translation.save()
      
      print '[MIGRATION:TRANSLATION]', name, language, translation
Exemple #6
0
def fetch_translation():
    basename = request.args.get('basename')
    sentences = Translation.objects(basename=basename).to_json()
    res = CustomResponse(Status.SUCCESS.value, json.loads(sentences))
    return res.getres()
Exemple #7
0
def main():
    args = parse_args()

    # Initialize
    dbmng = DBManager(args.db)

    # Only one session to access to database
    _session = dbmng.get_session()

    # Open the file
    decorder = json.JSONDecoder(object_pairs_hook=collections.OrderedDict)
    input_f = open(args.input_file, 'r')
    input_j = decorder.decode(input_f.read())

    # Load json keys and make it inserted
    nowtime = datetime.datetime.now()

    for key in input_j.keys():
        if key == 'translations':
            for dic in input_j[key]:
                rec = Translation(id=dic['id'],
                                  locale=dic['locale'],
                                  t=dic['t'],
                                  created_at=nowtime,
                                  created_by='rightctl_initializer')
                _session.add(rec)
            else:
                _session.commit()

        elif key == 'rights':
            for dic in input_j[key]:
                rec = Right(action=dic['action'],
                            enable_flag=True,
                            created_at=nowtime,
                            created_by='rightctl_initializer')
                _session.add(rec)
            else:
                _session.commit()

        elif key == 'policies':
            for dic in input_j[key]:
                rec = Policy(id=dic['id'],
                             policy_tid=dic['policy_tid'],
                             created_at=nowtime,
                             created_by='rightctl_initializer')
                _session.add(rec)
                _session.commit()
                for right_s in dic['rights']:
                    right = _session.query(Right).filter(
                        Right.action == right_s).one()
                    child = PolicyHasRight(policy_id=rec.id, right_id=right.id)
                    _session.add(child)
                else:
                    _session.commit()
            else:
                _session.commit()

        elif key == 'roles':
            for dic in input_j[key]:
                rec = Role(id=dic['id'],
                           role_tid=dic['role_tid'],
                           created_at=nowtime,
                           created_by='rightctl_initializer')
                _session.add(rec)
                _session.commit()
                for policy_s in dic['policies']:
                    policy = _session.query(Policy).filter(
                        Policy.id == policy_s).one()
                    child = RoleHasPolicy(role_id=rec.id, policy_id=policy.id)
                    _session.add(child)
                else:
                    _session.commit()
            else:
                _session.commit()

        else:
            None
    line_count = 0

    for line in f:

        if not line.strip():
            print('file end')
            break

        # print(line)
        surah_number, ayat_number, *line_text = line.strip().split('|')
        text = ' '.join(line_text)
        print('For File ' + edition_id + ' writing line...' + str(line_count))

        trans_id = surah_number + '-' + ayat_number

        translation = Translation()
        translation.id = edition_id + "_" + trans_id
        translation.ayah_id = trans_id
        translation.edition_id = edition_id
        translation.text = text.strip()
        translation.ayah_number = line_count
        translation.save(batch=trans_batch)

        line_count += 1
        count += 1

        if (count >= 400):
            trans_batch.commit()
            count = 0

    print('============Complete=============================')
Exemple #9
0
def translateFile():
    pool = mp.Pool(mp.cpu_count())
    basename = str(int(time.time()))
    current_time = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
    f = request.files['file']
    filepath = os.path.join(
        app.config['UPLOAD_FOLDER'], basename + '.pdf')
    translationProcess = TranslationProcess(
        status=STATUS_PROCESSING, name=f.filename, created_on=current_time, basename=basename)
    translationProcess.save()
    f.save(filepath)
    pool.apply_async(converttoimage, args=(
        filepath, app.config['UPLOAD_FOLDER'], basename, '_hin'), callback=capturetext)
    pool.close()
    pool.join()
    filtertext(app.config['UPLOAD_FOLDER'] + '/'+basename+'_hin.txt',
               app.config['UPLOAD_FOLDER'] + '/'+basename+'_hin_filtered.txt')
    processenglish(app.config['UPLOAD_FOLDER'] +
                 '/'+basename+'_hin_filtered.txt')
    translatewithanuvadaeng(app.config['UPLOAD_FOLDER'] +
                         '/'+basename+'_hin_filtered.txt', app.config['UPLOAD_FOLDER'] +
                         '/'+basename+'_eng_tran.txt')
    f_eng = open(app.config['UPLOAD_FOLDER']+'/' +
                 basename + '_eng_tran.txt', 'r')
    english_res = []
    hindi_res = []
    for f in f_eng:
        english_res.append(f)
    f_eng.close()
    f_hin = open(app.config['UPLOAD_FOLDER']+'/' +
                 basename + '_hin_filtered.txt', 'r')
    index = 0
    previousY = 0
    previousX = 0
    previousH = 0
    previousP = ''
    text_y = {}
    text_x = 0
    for f in f_hin:
        hindi_res.append(f)
        print(f)
        point = fetchwordhocrfromsentence(f, basename)
        english = english_res[index]
        words = english.split(' ')
        wordIndex = 0
        
        for word in words:
            try:
                if point['values'] is not None and point['values'][wordIndex] is not None and point['values'][wordIndex]['height'] is not None:
                    previousY = point['values'][wordIndex]['left']
                    previousX = point['values'][wordIndex]['top']
                    previousH = point['values'][wordIndex]['height']
                    try:
                        if text_y[point['values'][wordIndex]['imagepath']] is None:
                            text_y[point['values'][wordIndex]['imagepath']] = 200
                    except Exception as e:
                        text_y[point['values'][wordIndex]['imagepath']] = 200
                    (text_x, vertical) = puttext(point['values'][wordIndex]['height'],200,text_y[point['values'][wordIndex]['imagepath']],english,point['values'][wordIndex]['imagepath'])
                    text_y[point['values'][wordIndex]['imagepath']] = vertical
                    # else:
                    #     (text_x, text_y) = puttext(point['values'][wordIndex]['height'],point['values'][wordIndex]['left'],point['values'][wordIndex]['top'],english,point['values'][wordIndex]['imagepath'])
                    previousP = point['values'][wordIndex]['imagepath']
                    break
            except Exception as e:
                previousY = previousY + 200
                # puttext(previousH,previousY,previousX,word,previousP)
            wordIndex = wordIndex + 1
            # puttext(point['values'][wordIndex]['left'],point['values'][wordIndex]['top'],word,point['values'][wordIndex]['imagepath'])
        index = index + 1
    f_hin.close()
    data = {'hindi': hindi_res, 'english': english_res}
    translations = []
    for i in range(0, len(hindi_res)):
        translation = Translation(basename=str(
            basename), source=hindi_res[i], target=english_res[i])
        translations.append(translation)
    Translation.objects.insert(translations)
    # for f in glob.glob(app.config['UPLOAD_FOLDER']+'/'+basename+'*'):
    #     os.remove(f)
    res = CustomResponse(Status.SUCCESS.value, data)
    translationProcess = TranslationProcess.objects(basename=basename)
    translationProcess.update(set__status=STATUS_PROCESSED)
    return res.getres()
surah.number_of_ayahs = 7
surah.revelation_type = 'Mecca'
surah.save()

surah = Surah()
surah.id = 'surah-2'
surah.number = 2
surah.name = 'surah-2-name'
surah.english_name = 'surah-2-english-name'
surah.number_of_ayahs = 7
surah.revelation_type = 'Mecca'
surah.save()


# import data for translation
translation = Translation()
translation.id = 'translation-ayah-1-edition-1'
translation.ayah_id = 'ayah-1'
translation.ayah_number = 1
translation.edition_id = 'edition-1'
translation.text = 'Translation for ayah-1 edition-1'
translation.save()

translation = Translation()
translation.id = 'translation-ayah-1-edition-2'
translation.ayah_id = 'ayah-1'
translation.ayah_number = 1
translation.edition_id = 'edition-2'
translation.text = 'Translation for ayah-1 edition-2'
translation.save()