Giter VIP home page Giter VIP logo

django-gettext-demo's Introduction

Tests for django / gettext translations

These are for educational purposes, to see / show what actually happens, the effect of putting _( in the wrong places, etc.

To use

make
make test

Explanation

This is the expected output:

in English
hello
Without a const
This time with plain percent outside!.
This time with plain percent inside!
This time with a formatstring: test value
This time with a external format: test value
---
now in spanish
hola
Sin una constante
Esta vez con una percent outside! sencillo.
This time with plain percent inside!
This time with a formatstring: test value
Esta vez con un formato externo: test value

Which shows that (from texts/texts.py):

# A plain translated value works:
>>> print(PLAIN_CONST)
'hola'

# A plain string inside a _() works:
>>> print(_("Without a const"))
'Sin una constante'

# Using `%s` inside the _(), but acutally doing the % interpolation
# outside of the _() works:
>>> print(_("This time with plain %s.") % 'percent outside!')
'Esta vez con una percent outside! sencillo.'

# Using % *inside* the _() doesn't work:
>>> print(_("This time with plain %s" % 'percent inside!'))
'This time with plain percent inside!'

# Using a f"" inside a _() doesn't work:
>>> print(_(f"This time with a formatstring: {test_value}"))
'This time with a formatstring: test value'

# Using a {} type string, and formatting it *outside* of the _() works:
>>> print(_("This time with a external format: {test_value}").format(test_value=test_value))
'Esta vez con un formato externo: test value'

Apologies for incorrect Spanish

To do your own tests

  • Edit the code in texts/texts.py.
  • make update_messages to update the translation input files.
  • Edit any translations in locale/es/LC_MESSAGES/django.po
  • make update_messages again to compile messages to .mo
  • make test to run your code.

django-gettext-demo's People

Contributors

danthedeckie avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.