1654570320
Lingua is a package with tools to extract translatable texts from your code, and to check existing translations. It replaces the use of the xgettext
command from gettext, or pybabel
from Babel.
The simplest way to extract all translatable messages is to point the pot-create
tool at the root of your source tree.
$ pot-create src
This will create a messages.pot
file containing all found messages.
There are three ways to tell lingua which files you want it to scan:
Specify filenames directly on the command line. For example:
$ pot-create main.py utils.py
Specify a directory on the command line. Lingua will recursively scan that directory for all files it knows how to handle.
$ pot-create src
Use the --files-from
parameter to point to a file with a list of files to scan. Lines starting with #
and empty lines will be ignored.
$ pot-create --files-from=POTFILES.in
You can also use the --directory=PATH
parameter to add the given path to the list of directories to check for files. This may sound confusing, but can be useful. For example this command will look for main.py
and utils.py
in the current directory, and if they are not found there in the ../src
directory:
$ pot-create --directory=../src main.py utils.py
In its default configuration lingua will use its python extractor for .py
files, its XML extractor for .pt
and .zpt
files and its ZCML extractor for .zcml
files. If you use different extensions you setup a configuration file which tells lingua how to process files. This file uses a simple ini-style format.
There are two types of configuration that can be set in the configuration file: which extractor to use for a file extension, and the configuration for a single extractor.
File extensions are configured in the extensions
section. Each entry in this section maps a file extension to an extractor name. For example to tell lingua to use its XML extractor for files with a .html
extension you can use this configuration:
[extensions]
.html = xml
To find out which extractors are available use the -list-extractors
option.
$ bin/pot-create --list-extractors
chameleon Chameleon templates (defaults to Python expressions)
python Python sources
xml Chameleon templates (defaults to Python expressions)
zcml Zope Configuration Markup Language (ZCML)
zope Zope templates (defaults to TALES expressions)
A section named extractor:<name> can be used to configure a specific extractor. For example to tell the XML extractor that the default language used for expressions is TALES instead of Python:
[extractor:xml]
default-engine = tales
Either place a global configuration file named .config/lingua
to your home folder or use the --config
option to point lingua to your configuration file.
$ pot-create -c lingua.cfg src
When working with large systems you may use multiple translation domains in a single source tree. Lingua can support that by filtering messages by domain when scanning sources. To enable domain filtering use the -d
option:
$ pot-create -d mydomain src
Lingua will always include messages for which it can not determine the domain. For example, take this Python code:
print(gettext(u'Hello, World'))
print(dgettext('mydomain', u'Bye bye'))
The first hello-message does not specify its domain and will always be included. The second line uses dgettext to explicitly specify the domain. Lingua will use this information when filtering domains.
You can add comments to messages to help translators, for example to explain how a text is used, or provide hints on how it should be translated. For chameleon templates this can be done using the i18n:comment
attribute:
<label i18n:comment="This is a form label" i18n:translate="">Password</label>
Comments are inherited, so you can put them on a parent element as well.
<form i18n:comment="This is used in the password reset form">
<label i18n:translate="">Password</label>
<button i18n:translate="">Change</button>
</form>
For Python code you can tell lingua to include comments by using the --add-comments
option. This will make Linua include all comments on the line(s) immediately preceeding (there may be no empty line in between) a translation call.
# This text should address the user directly.
return _('Thank you for using our service.')
Alternatively you can also put a comment at the end of the line starting your translation function call.
return _('Thank you for using our service.') # Address the user directly
If you do not want all comments to be included but only specific ones you can add a keyword to the --add-comments
option, for example --add-comments=I18N
.
# I18N This text should address the user directly, and use formal addressing.
return _('Thank you for using our service')
Messages can have flags. These are to indicate what format a message has, and are typically used by validation tools to check if a translation does not break variable references or template syntax. Lingua does a reasonable job to detect strings using C and Python formatting, but sometimes you may need to set flags yourself. This can be done with a [flag, flag]
marker in a comment.
# I18N [markdown,c-format]
header = _(u'# Hello *%s*')
When looking for messages a lingua parser uses a default list of keywords to identify translation calls. You can add extra keywords via the --keyword
option. If you have your own mygettext
function which takes a string to translate as its first parameter you can use this:
$ pot-create --keyword=mygettext
If your function takes more parameters you will need to tell lingua about them. This can be done in several ways:
<keyword>:<parameter number>
. For example if you use i18n_log(level, msg)
the keyword specifier would be i18n_log:2
show_result(single, plural)
the keyword specifier is show_result:1,2
c
to the parameter number. For example the keyword specifier for pgettext
is pgettext:1c,2
.d
to the parameter number. For example the keyword specifier for dgettext
is dgettext:1d,2
. This is a lingua-specified extension.t
postfix. For example if a function must have four parameters to be a valid call, the specifier could be myfunc:1,4t
.Lingua includes a number of extractors:
There are several packages with plugins for Babel's message extraction tool. Lingua can use those plugins as well. The plugin names will be prefixed with babel-
to distinguish them from lingua extractors.
For example, if you have the PyBabel-json package installed you can instruct lingua to use it for .json files by adding this to your configuration file:
[extensions]
.json = babel-json
Some Babel plugins require you to specify comment tags. This can be set with the comment-tags
option.
[extractor:babel-mako]
comment-tags = TRANSLATOR:
Differences compared to GNU gettext:
Differences compared to Babel:
Lingua includes a simple polint
tool which performs a few basic checks on PO files. Currently implemented tests are:
msgfmt
). These should never happen and are usually a result of a bug in the message extraction logic.To check a po file simply run polint
with the po file as argument:
$ polint nl.po
Translation:
${val} ist keine Zeichenkette
Used for 2 canonical texts:
1 ${val} is not a string
2 "${val}" is not a string
First we need to create the custom extractor:
from lingua.extractors import Extractor
from lingua.extractors import Message
class MyExtractor(Extractor):
'''One-line description for --list-extractors'''
extensions = ['.txt']
def __call__(self, filename, options):
return [Message(None, 'msgid', None, [], u'', u'', (filename, 1))]
Hooking up extractors to lingua is done by lingua.extractors
entry points in setup.py
:
setup(name='mypackage',
...
install_requires=[
'lingua',
],
...
entry_points='''
[lingua.extractors]
my_extractor = mypackage.extractor:MyExtractor
'''
...)
Note - the registered extractor must be a class derived from the Extractor
base class.
After installing mypackage
lingua will automatically detect the new custom extractor.
There exists a helper shell script for managing translations of packages in docs/examples
named i18n.sh
. Copy it to package root where you want to work on translations, edit the configuration params inside the script and use:
./i18n.sh lang
for initial catalog creation and:
./i18n.sh
for updating translation and compiling the catalog.
zope: a variant of the chameleon extractor, which assumes the default
expression language is TALES instead of Python.
Author: wichert
Source Code: https://github.com/wichert/lingua
License: View license
1619510796
Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.
Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is
Syntax: x = lambda arguments : expression
Now i will show you some python lambda function examples:
#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map
1626775355
No programming language is pretty much as diverse as Python. It enables building cutting edge applications effortlessly. Developers are as yet investigating the full capability of end-to-end Python development services in various areas.
By areas, we mean FinTech, HealthTech, InsureTech, Cybersecurity, and that's just the beginning. These are New Economy areas, and Python has the ability to serve every one of them. The vast majority of them require massive computational abilities. Python's code is dynamic and powerful - equipped for taking care of the heavy traffic and substantial algorithmic capacities.
Programming advancement is multidimensional today. Endeavor programming requires an intelligent application with AI and ML capacities. Shopper based applications require information examination to convey a superior client experience. Netflix, Trello, and Amazon are genuine instances of such applications. Python assists with building them effortlessly.
Python can do such numerous things that developers can't discover enough reasons to admire it. Python application development isn't restricted to web and enterprise applications. It is exceptionally adaptable and superb for a wide range of uses.
Robust frameworks
Python is known for its tools and frameworks. There's a structure for everything. Django is helpful for building web applications, venture applications, logical applications, and mathematical processing. Flask is another web improvement framework with no conditions.
Web2Py, CherryPy, and Falcon offer incredible capabilities to customize Python development services. A large portion of them are open-source frameworks that allow quick turn of events.
Simple to read and compose
Python has an improved sentence structure - one that is like the English language. New engineers for Python can undoubtedly understand where they stand in the development process. The simplicity of composing allows quick application building.
The motivation behind building Python, as said by its maker Guido Van Rossum, was to empower even beginner engineers to comprehend the programming language. The simple coding likewise permits developers to roll out speedy improvements without getting confused by pointless subtleties.
Utilized by the best
Alright - Python isn't simply one more programming language. It should have something, which is the reason the business giants use it. Furthermore, that too for different purposes. Developers at Google use Python to assemble framework organization systems, parallel information pusher, code audit, testing and QA, and substantially more. Netflix utilizes Python web development services for its recommendation algorithm and media player.
Massive community support
Python has a steadily developing community that offers enormous help. From amateurs to specialists, there's everybody. There are a lot of instructional exercises, documentation, and guides accessible for Python web development solutions.
Today, numerous universities start with Python, adding to the quantity of individuals in the community. Frequently, Python designers team up on various tasks and help each other with algorithmic, utilitarian, and application critical thinking.
Progressive applications
Python is the greatest supporter of data science, Machine Learning, and Artificial Intelligence at any enterprise software development company. Its utilization cases in cutting edge applications are the most compelling motivation for its prosperity. Python is the second most well known tool after R for data analytics.
The simplicity of getting sorted out, overseeing, and visualizing information through unique libraries makes it ideal for data based applications. TensorFlow for neural networks and OpenCV for computer vision are two of Python's most well known use cases for Machine learning applications.
Thinking about the advances in programming and innovation, Python is a YES for an assorted scope of utilizations. Game development, web application development services, GUI advancement, ML and AI improvement, Enterprise and customer applications - every one of them uses Python to its full potential.
The disadvantages of Python web improvement arrangements are regularly disregarded by developers and organizations because of the advantages it gives. They focus on quality over speed and performance over blunders. That is the reason it's a good idea to utilize Python for building the applications of the future.
#python development services #python development company #python app development #python development #python in web development #python software development
1602968400
Python is awesome, it’s one of the easiest languages with simple and intuitive syntax but wait, have you ever thought that there might ways to write your python code simpler?
In this tutorial, you’re going to learn a variety of Python tricks that you can use to write your Python code in a more readable and efficient way like a pro.
Swapping value in Python
Instead of creating a temporary variable to hold the value of the one while swapping, you can do this instead
>>> FirstName = "kalebu"
>>> LastName = "Jordan"
>>> FirstName, LastName = LastName, FirstName
>>> print(FirstName, LastName)
('Jordan', 'kalebu')
#python #python-programming #python3 #python-tutorials #learn-python #python-tips #python-skills #python-development
1603047600
In this tutorial, we will explore different possibilities to translate a text or word using python. From my experience, this is very helpful if you want to automate the translation of many paragraphs, sentences or words.
Furthermore, you can have a backend worker, which receives new data constantly and can either return a request with the translation or store different translations in a database (this is very useful in NLP tasks).
One of the reasons to choose Python apart from the clear syntax and the extensive library is the great community that works extensively on the development of the language itself or extending the functionality with third party modules.
Precisely, one of the modules that makes it straightforward to translate texts is the deep_translator, which provides support for multiple famous translators.
#python #google-translate #translation #translators #translate
1602666000
Today you’re going to learn how to use Python programming in a way that can ultimately save a lot of space on your drive by removing all the duplicates.
In many situations you may find yourself having duplicates files on your disk and but when it comes to tracking and checking them manually it can tedious.
Heres a solution
Instead of tracking throughout your disk to see if there is a duplicate, you can automate the process using coding, by writing a program to recursively track through the disk and remove all the found duplicates and that’s what this article is about.
But How do we do it?
If we were to read the whole file and then compare it to the rest of the files recursively through the given directory it will take a very long time, then how do we do it?
The answer is hashing, with hashing can generate a given string of letters and numbers which act as the identity of a given file and if we find any other file with the same identity we gonna delete it.
There’s a variety of hashing algorithms out there such as
#python-programming #python-tutorials #learn-python #python-project #python3 #python #python-skills #python-tips