-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/jbcodeforce/python-code
- Loading branch information
Showing
7 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
## The localization examples | ||
|
||
How to make a string translated in another language using GNU gettext. | ||
|
||
See the code test_localize.py | ||
|
||
* install poedit | ||
* upadte PATH to point to `C:\Program Files (x86)\Poedit\GettextTools\bin` | ||
* get the localizable string from the python program | ||
* xgettext -d app -o localize/app.pot test_localize.py | ||
* then create localize/fr/LC_MESSAGES/app.po from the created app.po under localize | ||
* Compile the po to mo: msgfmt -o localize/fr/LC_MESSAGES/app.mo localize/fr/LC_MESSAGES/app | ||
* export LANG=fr | ||
* python test_localize.py | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# SOME DESCRIPTIVE TITLE. | ||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | ||
# This file is distributed under the same license as the PACKAGE package. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-03-25 21:09-0700\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <LL@li.org>\n" | ||
"Language: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=CHARSET\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
|
||
#: test_localize.py:6 | ||
msgid "This is a translatable string." | ||
msgstr "" | ||
|
||
#: test_localize.py:8 | ||
msgid "Your name." | ||
msgstr " |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-03-25 21:09-0700\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <LL@li.org>\n" | ||
"Language: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=CHARSET\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
|
||
|
||
msgid "This is a translatable string." | ||
msgstr "Ceci est une chaine de charactere traduisable" | ||
|
||
msgid "Your name." | ||
msgstr "Votre nom" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import math | ||
|
||
def exponential(base,exp): | ||
if base == 0: | ||
return 0 | ||
if exp == 0: | ||
return 1 | ||
else: | ||
if exp > 0: | ||
return base * exponential(base,exp-1) | ||
else: | ||
return 1/base * exponential(base,exp+1) | ||
|
||
|
||
if __name__ == "__main__": | ||
print(exponential(0,2)) | ||
print(exponential(2,3)) | ||
assert exponential(2,-3) == math.pow(2,-3) | ||
print(exponential(5,-5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import gettext | ||
|
||
|
||
localizator = gettext.translation('app', localedir='localize', languages=['fr']) | ||
localizator.install() | ||
|
||
_ = localizator.gettext | ||
# ... | ||
print(_('This is a translatable string.')) | ||
|
||
print(_('Your name.')) |