Skip to content

Enable localization and add empty Spanish po file #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: v0.7.10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,66 @@ After setting up your development environment you may run tests.
python manage.py test django_ledger
```

# Adding new localization

- Choose the desired locale in the form `ll` or `ll_CC` as described in the [official Django documentation](https://docs.djangoproject.com/en/5.2/topics/i18n/#term-locale-name). For example, to translate to a region/country specific language like `Spanish (Mexico)`, your `ll_CC` string should be `es_MX`. To translate to `French` (international, not region/country specific), you just use the `ll` string `fr`.

1. Generate the *.po file containing all the strings that need translation for your selected locale using the command `django-admin makemessages -l <ll|ll_CC>`. Examples:

```bash
$ django-admin makemessages -l es_MX --ignore assets/node_modules
$ django-admin makemessages -l fr --ignore assets/node_modules
```

Note: The `node_modules` folder needs to be explicitly ignored because it is traversed by default, but it contains hundreds of unrelated external dependencies that do not contain strings for django to translate. Plus, many of those files contain bytes that can't be decoded, which can show several warnings or errors.

1. If you also added gettext calls to javascript or typescript, you need additional steps:

- First, you add your gettext calls to js and ts files. For example

```typescript
let i_and_e = gettext('Income and Expenses')
```
- Then, you compile the typescript code (assuming you already installed all the required dependencies):

```bash
$ cd assets/
$ npm run build
$ cd ../
```

- Now you generate the javascript specific po file by analyzing only the Django Ledger specific js and ts files:

```bash
$ django-admin makemessages -l es_MX -d djangojs --ignore assets/node_modules --extension=js,ts
```

1. Open your generated localization files:

- From *.py, *.html files: `locale/<ll|ll_CC>/LC_MESSAGES/django.po`
- From *.js, *.ts files: `locale/<ll|ll_CC>/LC_MESSAGES/djangojs.po`

Translate the English strings to your desired language inside the `msgstr` placeholders. Make sure to fix fuzzy strings too, if you find any, because they are ambigous strings and won't show up unless fixed.

1. Compile the translated messages using:

```bash
$ django-admin compilemessages
```

1. Open the `dev_env/settings.py` file and change `LANGUAGE_CODE` to your new language code. It's in the format `ll-cc` or `ll`, as described in the [official Django documentation](https://docs.djangoproject.com/en/5.2/topics/i18n/#term-language-code). Examples:

```python
LANGUAGE_CODE = 'es-mx'
```

or

```python
LANGUAGE_CODE = 'fr'
```
1. Run the server with `python manage.py runserver`. Your strings should show up in your selected locale and language.

# Screenshots

![django ledger entity dashboard](https://us-east-1.linodeobjects.com/django-ledger/public/img/django_ledger_entity_dashboard.png)
Expand Down
1 change: 1 addition & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"chart.js": "^4.4.9",
"iconify-icon": "^2.3.0",
"json-schema": "^0.4.0",
"moment": "^2.30.1",
"pikaday": "^1.8.2",
"scss-tokenizer": "^0.4.3",
"trim-newlines": "^4.1.1",
Expand Down
1 change: 1 addition & 0 deletions assets/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare function gettext(msgid: string): string;
2 changes: 2 additions & 0 deletions dev_env/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
USE_I18N = True
USE_L10N = True

LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

Expand Down
2 changes: 1 addition & 1 deletion django_ledger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
default_app_config = 'django_ledger.apps.DjangoLedgerConfig'

"""Django Ledger"""
__version__ = '0.7.8'
__version__ = '0.7.9'
__license__ = 'GPLv3 License'

__author__ = 'Miguel Sanda'
Expand Down
1 change: 0 additions & 1 deletion django_ledger/models/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ class AccountModelAbstract(MP_Node, CreateUpdateMixIn):
on_delete=models.CASCADE,
verbose_name=_('Chart of Accounts'))
objects = AccountModelManager()
node_order_by = ['uuid']

class Meta:
abstract = True
Expand Down
9 changes: 7 additions & 2 deletions django_ledger/models/data_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

from decimal import Decimal
from typing import Optional, Set, Dict, List
from typing import Optional, Set, Dict, List, Union
from uuid import uuid4, UUID

from django.core.exceptions import ValidationError
Expand All @@ -24,6 +24,7 @@

from django_ledger.io import ASSET_CA_CASH, CREDIT, DEBIT
from django_ledger.models import JournalEntryModel
from django_ledger.models.entity import EntityModel
from django_ledger.models.mixins import CreateUpdateMixIn
from django_ledger.models.utils import lazy_loader

Expand Down Expand Up @@ -128,8 +129,12 @@ def for_user(self, user_model):

)

def for_entity(self, entity_slug: str, user_model):
def for_entity(self, entity_slug: Union[EntityModel, str], user_model):
qs = self.for_user(user_model)
if isinstance(entity_slug, EntityModel):
return qs.filter(
Q(bank_account_model__entity_model=entity_slug)
)
return qs.filter(
Q(bank_account_model__entity_model__slug__exact=entity_slug)
)
Expand Down
1 change: 0 additions & 1 deletion django_ledger/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,6 @@ class EntityModelAbstract(MP_Node,
meta = models.JSONField(default=dict, null=True, blank=True)
objects = EntityModelManager.from_queryset(queryset_class=EntityModelQuerySet)()

node_order_by = ['uuid']

class Meta:
abstract = True
Expand Down
1 change: 0 additions & 1 deletion django_ledger/models/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class EntityUnitModelAbstract(MP_Node,
hidden = models.BooleanField(default=False, verbose_name=_('Is Hidden'))

objects = EntityUnitModelManager.from_queryset(queryset_class=EntityUnitModelQuerySet)()
node_order_by = ['uuid']

class Meta:
abstract = True
Expand Down
Loading