Skip to content
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

Adds a language option to the update_translation_fields commands #563

Merged
merged 5 commits into from
Aug 18, 2020
Merged

Adds a language option to the update_translation_fields commands #563

merged 5 commits into from
Aug 18, 2020

Conversation

MrCordeiro
Copy link
Contributor

@MrCordeiro MrCordeiro commented Aug 7, 2020

Now, not only the default language will have its translation field populated, but you can provide a --language option to populate any other language listed on your settings.py.

My use case was as follows:

I needed to search an Object by its name field, like so:

Object.objects.filter(name__icontains="query")

But when someone from Italy tried searching for a translatable object, it would look for the name_it field only. If that field was empty, it wouldn't search into the default name field as well. The most straightforward solution was to populate all translatable fields regardless of whether they were using the default language or not.

So, if I run:

python manage.py update_translation_fields --language it

All the empty name_it fields that are empty will contain the value from the name field.

pyproject.toml Outdated
[tool.poetry.dev-dependencies]
pdbpp = "^0.10.2"
flake8 = "^3.7.9"
six = "^1.15.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are your files contains ^M characters?

https://stackoverflow.com/questions/1889559/git-diff-to-ignore-m

Copy link
Contributor Author

@MrCordeiro MrCordeiro Aug 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea... Maybe because I'm on Windows?
Tried editing the file on Github, but it didn't work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I delete this file?
I've only added six because the test suite wouldn't run otherwise, but it not integral to the PR.

Copy link
Contributor Author

@MrCordeiro MrCordeiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to fix the unused COMMASPACE variable

Copy link
Contributor Author

@MrCordeiro MrCordeiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIxed COMMASPACE, but need advice on ^M issue.

pyproject.toml Outdated
[tool.poetry.dev-dependencies]
pdbpp = "^0.10.2"
flake8 = "^3.7.9"
six = "^1.15.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I delete this file?
I've only added six because the test suite wouldn't run otherwise, but it not integral to the PR.

@last-partizan
Copy link
Collaborator

@MrCordeiro yes, you'd better delete this line.

If you install it with poetry install, it should be installed from setup.py as dependency along with django.

@last-partizan
Copy link
Collaborator

@MrCordeiro as for advice on ^M - have you followed link to stackoverflow? https://stackoverflow.com/questions/1889559/git-diff-to-ignore-m

You should enable git config --global core.autocrlf true.

@MrCordeiro
Copy link
Contributor Author

@MrCordeiro yes, you'd better delete this line.

If you install it with poetry install, it should be installed from setup.py as dependency along with django.

Line deleted, as it was merely ancillary.

(I had followed the link, but was unable to understand that stackoverflow discussion :-/ ...)

@last-partizan last-partizan merged commit ac91740 into deschler:master Aug 18, 2020
@last-partizan
Copy link
Collaborator

Thanks, merged it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants