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
synctranslationscommand:$ python manage.py synctranslations
- help¶
The command’s help text.
- execute(*args, **options)[source]¶
Execute the
CommandwithBaseCommandarguments.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
Commandaccepts on anArgumentParser.Defines the different types of arguments that the
Commandaccepts on theArgumentParser.- Parameters:
parser (ArgumentParser) – The parser to add the arguments that the
Commandaccepts on.
- get_content_types(*app_labels)[source]¶
Return the
ContentTypes in some apps or all of them.If the app labels are passed in it returns the
ContentTypes in those apps, if nothing is passed in it returns theContentTypes in all apps.- Parameters:
app_labels (list(str)) – The apps in which to get the
ContentTypes.- Returns:
The
ContentTypes in the apps.- Return type:
To get the
ContentTypes (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
ContentTypes (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
ContentTypes.Returns the obsolete translations of the
ContentTypes based on the current configurations of their models.- Parameters:
content_types (QuerySet(ContentType)) – The
ContentTypes to get the obsolete translations of.- Returns:
The obsolete translations of the
ContentTypes.- Return type:
To get the obsolete translations of some
ContentTypes: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: