Reference: synctranslations¶
This module contains the synctranslations command for the Translations app.
- class translations.management.commands.synctranslations.Command[source]¶
The command which synchronizes the translations with the apps models configurations.
To use the
synctranslations
command:$ python manage.py synctranslations
- help¶
The command’s help text.
- execute(*args, **options)[source]¶
Execute the
Command
withBaseCommand
arguments.This is an overriden version of the
BaseCommand
‘sexecute()
method. It defines the standard input on theCommand
.
- add_arguments(parser)[source]¶
Add the arguments that the
Command
accepts on anArgumentParser
.Defines the different types of arguments that the
Command
accepts on theArgumentParser
.- Parameters
parser (ArgumentParser) – The parser to add the arguments that the
Command
accepts on.
- get_content_types(*app_labels)[source]¶
Return the
ContentType
s in some apps or all of them.If the app labels are passed in it returns the
ContentType
s in those apps, if nothing is passed in it returns theContentType
s in all apps.- Parameters
app_labels (list(str)) – The apps in which to get the
ContentType
s.- Returns
The
ContentType
s in the apps.- Return type
To get the
ContentType
s (in some apps):from translations.management.commands.synctranslations import Command command = Command() content_types = command.get_content_types('sample').values_list( 'app_label', 'model') print(sorted(content_types))
[ ('sample', 'city'), ('sample', 'continent'), ('sample', 'country'), ('sample', 'timezone'), ]
To get the
ContentType
s (in all apps):from translations.management.commands.synctranslations import Command command = Command() content_types = command.get_content_types().values_list( 'app_label', 'model') print(sorted(content_types))
[ ('admin', 'logentry'), ('auth', 'group'), ('auth', 'permission'), ('auth', 'user'), ('contenttypes', 'contenttype'), ('sample', 'city'), ('sample', 'continent'), ('sample', 'country'), ('sample', 'timezone'), ('sessions', 'session'), ('translations', 'translation'), ]
- get_obsolete_translations(content_types)[source]¶
Return the obsolete translations of some
ContentType
s.Returns the obsolete translations of the
ContentType
s based on the current configurations of their models.- Parameters
content_types (QuerySet(ContentType)) – The
ContentType
s to get the obsolete translations of.- Returns
The obsolete translations of the
ContentType
s.- Return type
To get the obsolete translations of some
ContentType
s:from translations.management.commands.synctranslations import Command command = Command() content_types = command.get_content_types('sample') obsolete_translations = command.get_obsolete_translations(content_types) print(obsolete_translations)
<QuerySet []>
- log_obsolete_translations(obsolete_translations)[source]¶
Log the details of some obsolete translations.
Logs the model and field details of the obsolete translations.
- Parameters
obsolete_translations (QuerySet(Translation)) – The obsolete translations to log the details of.
- ask_yes_no(message, default=None)[source]¶
Ask the user for yes or no with a message and a default value.
Prompts the user with the message asking them for a yes or no answer, optionally a default value can be set for the answer.
- should_run_synchronization()[source]¶
Return whether to run the synchronization or not.
Determines whether the synchronization should run or not. It does so by making sure that the user is aware of the risks. If the user is using a TTY it asks them whether they are sure or not and if the user is NOT using a TTY they have to explicitly declare that they are sure in the command.
- Returns
whether to run the synchronization or not.
- Return type