Implemented Transifex

This commit is contained in:
Mohammad Osama Khan 2022-12-14 13:05:57 +05:30
parent 88a061a0ff
commit ee0e081983
No known key found for this signature in database
GPG Key ID: 15F978BEFADAB9E1
4 changed files with 58 additions and 10 deletions

15
Dockerfile Normal file
View File

@ -0,0 +1,15 @@
# #Deriving the latest base image
# FROM python:latest
# WORKDIR /transifex-webhook
# ENV
# COPY requirements.txt requirements.txt
# RUN pip install -r requirements.txt
# COPY transifex_demo.py ./
# COPY . .
# CMD [ "python", "./transifex_demo.py"]
FROM python:3
ADD requirements.txt /
RUN pip install -r requirements.txt
ADD transifex_demo.py /
CMD [ "python", "./transifex_demo.py" ]

10
docker-compose.yml Normal file
View File

@ -0,0 +1,10 @@
# docker-compose.yml
version: '2'
services:
service-name:
image: transifex-docker
# environment:
# - GREETING=hello
env_file:
- ./transifex.env

16
requirements.txt Normal file
View File

@ -0,0 +1,16 @@
asttokens==2.2.1
certifi==2022.12.7
charset-normalizer==2.1.1
click==8.1.3
future==0.18.2
idna==3.4
parsimonious==0.10.0
pyseeyou==1.0.2
python-dotenv==0.21.0
pytz==2022.6
regex==2022.10.31
requests==2.28.1
six==1.16.0
toolz==0.12.0
transifex-python==3.0.3
urllib3==1.26.13

View File

@ -1,14 +1,21 @@
from transifex.native.daemon import daemon
"""Transifex basic implementation using python native sdk """
import os
from dotenv import load_dotenv
from transifex.native import init, tx
from transifex.native.rendering import PseudoTranslationPolicy, SourceStringErrorPolicy
from transifex.native.parsing import SourceString
init(token='1/6e212800e39991406f0001245517708823f293b8', languages=['el', 'fr', 'en'], secret='1/47cc0fcea6d5f229a618ae0a20e2b60113738fe1')
# Add some strings to push
strings = [SourceString('My Addresses')]
env_path=os.path.join('transifex.env')
if os.path.exists(env_path):
load_dotenv(env_path)
token = os.getenv('token')
secret = os.getenv('secret')
init(token=token, languages=['el', 'fr', 'en'], secret=secret)
# Add some strings to push
strings = [SourceString('My Addresses')]
response_content = tx.push_source_strings(strings)
tx.fetch_translations()
el_translation = tx.translate('My Addresses', 'fr')
print(el_translation)
response_content = tx.push_source_strings(strings)
print(response_content)
tx.fetch_translations()
el_translation = tx.translate('My Addresses', 'fr')
print(el_translation)
else:
raise NotADirectoryError("transifex.env")