Following stackoverflow posts and a lot of tutorials to implement i18n internationalization in Django Admin I founded this steps:
Command line Install (in the right ENV)
Using PIP: pip install python-gettext (I tried this)
Using Conda: conda install gettext
settings.py
MIDDLEWARE = [
...
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware', #right place
'django.middleware.common.CommonMiddleware',
...
]
...'context_processors': [
...
'django.template.context_processors.i18n', # Indifferent place
...
]
...
TIME_ZONE = 'UTC' # America/Sao_Paulo
USE_I18N = True
USE_L10N = True
USE_TZ = True
ugettext = lambda s: s
LANGUAGES = (
( 'en-us', ugettext( 'English' )),
( 'pt-br', ugettext( 'Portuguese' )),
( 'es', ugettext( 'Spanish' )),
)
LANGUAGE_CODE = 'en-us' #default
...
SITE_ROOT = os.path.dirname( os.path.realpath( __file__ ) )
PROJECT_PATH = os.path.abspath( os.path.dirname( __name__ ) )
LOCALE_PATHS = ( os.path.join( SITE_ROOT, 'locale' ), ) # translation files will be created into 'locale' folder from root project folder
urls.py
admin.autodiscover()
urlpatterns = [
url( r'^favicon.ico$',
RedirectView.as_view( url = staticfiles_storage.url( 'images/favicon.png' ), ),
),
...
]
<b>urlpatterns += i18n_patterns</b>(
path( r'admin/',
admin.site.urls
),
...
)
urlpatterns += static(
settings.STATIC_URL, document_root = settings.STATIC_ROOT ) \
+ static(
settings.MEDIA_URL, document_root = settings.MEDIA_ROOT )
models.py (any)
from django.core.validators import RegexValidator
from django.db import models
from django.utils.translation import ugettext as _
...
class BusinessType(models.Model):
businesstype_name = models.CharField(
verbose_name = _( 'Business Name' ),
help_text = _( 'Name, Field Type, Activity' ),
max_length = 32, )
Windows Users (must have)
Windows users need to download two packages from gnome project to built the i18n internationalization translation files to the right folder/directory - so download this to properly Windows 64/32 bits system gettext-runtime-(last file version)_win64 or win32 and download gettext-tools-(last file version) too, Decompress all files to the same folder(gettext-tools inside BIN folder) and add Windows PATH variable to recognize these files.
MAC Users (must check this)
I read a lot misspelled texts talking about the case/camel-Case into "languages" code are case sensitive, so take care if you use something like pt-Br:
LANGUAGES = (
( 'en-us', ugettext( 'English' )),
( 'pt-br', ugettext( 'Portuguese' )),
( 'es', ugettext( 'Spanish' )),
)
Building templates files(.po) (to write translations)
At terminal try this to built all specified languages in LANGUAGES and put "-v 3" to show how magic happening
python manage.py makemessages --all -v 3
Nothing happens (Someone have the same no-error like this)
All this steps results into a 'locale' folder created, a 'python manage.py makemessages' supposedly worked and listing none, creating none, doing nothing, even not one error. I'm really lost about this and after that, how I can retrieve the current selected language code to create alternative code to impossible i18n translations like:
PHONE REGEX rules, STATE list,...