mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
10300 initial translation support use gettext
This commit is contained in:
@@ -5,6 +5,7 @@ from django import forms
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
|
||||
from django.db.models import Q
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from utilities.choices import unpack_grouped_choices
|
||||
from utilities.forms.utils import parse_csv, validate_csv
|
||||
@@ -50,9 +51,9 @@ class CSVDataField(forms.CharField):
|
||||
if not self.initial:
|
||||
self.initial = ','.join(self.required_fields) + '\n'
|
||||
if not self.help_text:
|
||||
self.help_text = 'Enter the list of column headers followed by one line per record to be imported, using ' \
|
||||
'commas to separate values. Multi-line data and values containing commas may be wrapped ' \
|
||||
'in double quotes.'
|
||||
self.help_text = _('Enter the list of column headers followed by one line per record to be imported, using '
|
||||
'commas to separate values. Multi-line data and values containing commas may be wrapped '
|
||||
'in double quotes.')
|
||||
|
||||
def to_python(self, value):
|
||||
reader = csv.reader(StringIO(value.strip()))
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import re
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from utilities.forms.constants import *
|
||||
from utilities.forms.utils import expand_alphanumeric_pattern, expand_ipaddress_pattern
|
||||
@@ -42,8 +43,8 @@ class ExpandableIPAddressField(forms.CharField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if not self.help_text:
|
||||
self.help_text = 'Specify a numeric range to create multiple IPs.<br />'\
|
||||
'Example: <code>192.0.2.[1,5,100-254]/24</code>'
|
||||
self.help_text = _('Specify a numeric range to create multiple IPs.<br />'
|
||||
'Example: <code>192.0.2.[1,5,100-254]/24</code>')
|
||||
|
||||
def to_python(self, value):
|
||||
# Hackish address family detection but it's all we have to work with
|
||||
|
@@ -4,6 +4,7 @@ from django import forms
|
||||
from django.db.models import Count
|
||||
from django.forms.fields import JSONField as _JSONField, InvalidJSONInput
|
||||
from django.templatetags.static import static
|
||||
from django.utils.translation import gettext as _
|
||||
from netaddr import AddrFormatError, EUI
|
||||
|
||||
from utilities.forms import widgets
|
||||
@@ -45,7 +46,7 @@ class SlugField(forms.SlugField):
|
||||
slug_source: Name of the form field from which the slug value will be derived
|
||||
"""
|
||||
widget = widgets.SlugWidget
|
||||
help_text = "URL-friendly unique shorthand"
|
||||
help_text = _("URL-friendly unique shorthand")
|
||||
|
||||
def __init__(self, *, slug_source='name', help_text=help_text, **kwargs):
|
||||
super().__init__(help_text=help_text, **kwargs)
|
||||
@@ -97,7 +98,7 @@ class JSONField(_JSONField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if not self.help_text:
|
||||
self.help_text = 'Enter context data in <a href="https://json.org/">JSON</a> format.'
|
||||
self.help_text = _('Enter context data in <a href="https://json.org/">JSON</a> format.')
|
||||
self.widget.attrs['placeholder'] = ''
|
||||
self.widget.attrs['class'] = 'font-monospace'
|
||||
|
||||
|
@@ -5,8 +5,9 @@ from io import StringIO
|
||||
|
||||
import yaml
|
||||
from django import forms
|
||||
from utilities.forms.utils import parse_csv
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from utilities.forms.utils import parse_csv
|
||||
from .choices import ImportFormatChoices
|
||||
from .widgets import APISelect, APISelectMultiple, ClearableFileInput, StaticSelect
|
||||
|
||||
@@ -103,7 +104,7 @@ class BulkRenameForm(BootstrapMixin, forms.Form):
|
||||
use_regex = forms.BooleanField(
|
||||
required=False,
|
||||
initial=True,
|
||||
label='Use regular expressions'
|
||||
label=_('Use regular expressions')
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
@@ -145,7 +146,7 @@ class ImportForm(BootstrapMixin, forms.Form):
|
||||
data = forms.CharField(
|
||||
required=False,
|
||||
widget=forms.Textarea(attrs={'class': 'font-monospace'}),
|
||||
help_text="Enter object data in CSV, JSON or YAML format."
|
||||
help_text=_("Enter object data in CSV, JSON or YAML format.")
|
||||
)
|
||||
data_file = forms.FileField(
|
||||
label="Data file",
|
||||
@@ -219,7 +220,7 @@ class FilterForm(BootstrapMixin, forms.Form):
|
||||
"""
|
||||
q = forms.CharField(
|
||||
required=False,
|
||||
label='Search'
|
||||
label=_('Search')
|
||||
)
|
||||
|
||||
|
||||
@@ -233,7 +234,7 @@ class TableConfigForm(BootstrapMixin, forms.Form):
|
||||
widget=forms.SelectMultiple(
|
||||
attrs={'size': 10, 'class': 'form-select'}
|
||||
),
|
||||
label='Available Columns'
|
||||
label=_('Available Columns')
|
||||
)
|
||||
columns = forms.MultipleChoiceField(
|
||||
choices=[],
|
||||
@@ -241,7 +242,7 @@ class TableConfigForm(BootstrapMixin, forms.Form):
|
||||
widget=forms.SelectMultiple(
|
||||
attrs={'size': 10, 'class': 'form-select'}
|
||||
),
|
||||
label='Selected Columns'
|
||||
label=_('Selected Columns')
|
||||
)
|
||||
|
||||
def __init__(self, table, *args, **kwargs):
|
||||
|
Reference in New Issue
Block a user