本文整理汇总了Python中weblate.trans.util.join_plural函数的典型用法代码示例。如果您正苦于以下问题:Python join_plural函数的具体用法?Python join_plural怎么用?Python join_plural使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了join_plural函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: perform_suggestion
def perform_suggestion(unit, form, request):
'''
Handle suggesion saving.
'''
if form.cleaned_data['target'][0] == '':
messages.error(request, _('Your suggestion is empty!'))
# Stay on same entry
return False
elif not can_suggest(request.user, unit.translation):
# Need privilege to add
messages.error(
request,
_('You don\'t have privileges to add suggestions!')
)
# Stay on same entry
return False
# Invite user to become translator if there is nobody else
recent_changes = Change.objects.content(True).filter(
translation=unit.translation,
).exclude(
user=None
)
if not recent_changes.exists():
messages.info(request, _(
'There is currently no active translator for this '
'translation, please consider becoming a translator '
'as your suggestion might otherwise remain unreviewed.'
))
# Create the suggestion
Suggestion.objects.add(
unit,
join_plural(form.cleaned_data['target']),
request,
)
return True
开发者ID:Yixf-Self,项目名称:weblate,代码行数:35,代码来源:edit.py
示例2: get_source
def get_source(self):
'''
Returns source string from a ttkit unit.
'''
if (isinstance(self.mainunit, tsunit) and
self.template is None and
self.mainunit.hasplural()):
# Need to apply special magic for plurals here
# as there is no singlular/plural in the source string
return join_plural([
self.unit.source,
self.unit.source,
])
if self.is_unit_key_value():
# Need to decode property encoded string
if isinstance(self.mainunit, propunit):
if self.template is not None:
return quote.propertiesdecode(self.template.value)
else:
return quote.propertiesdecode(self.unit.name)
if self.template is not None:
return self.template.value
else:
return self.unit.name
else:
if self.template is not None:
return get_string(self.template.target)
else:
return get_string(self.unit.source)
开发者ID:franco999,项目名称:weblate,代码行数:29,代码来源:formats.py
示例3: perform_suggestion
def perform_suggestion(unit, form, request):
"""
Handle suggesion saving.
"""
if form.cleaned_data["target"][0] == "":
messages.error(request, _("Your suggestion is empty!"))
# Stay on same entry
return False
elif not request.user.has_perm("trans.add_suggestion"):
# Need privilege to add
messages.error(request, _("You don't have privileges to add suggestions!"))
# Stay on same entry
return False
# Invite user to become translator if there is nobody else
recent_changes = Change.objects.content(True).filter(translation=unit.translation).exclude(user=None)
if not recent_changes.exists():
messages.info(
request,
_(
"There is currently no active translator for this "
"translation, please consider becoming a translator "
"as your suggestion might otherwise remain unreviewed."
),
)
# Create the suggestion
Suggestion.objects.add(unit, join_plural(form.cleaned_data["target"]), request)
return True
开发者ID:paour,项目名称:weblate,代码行数:27,代码来源:edit.py
示例4: perform_suggestion
def perform_suggestion(unit, form, request):
"""Handle suggesion saving."""
if form.cleaned_data['target'][0] == '':
messages.error(request, _('Your suggestion is empty!'))
# Stay on same entry
return False
if not request.user.has_perm('suggestion.add', unit.translation):
# Need privilege to add
messages.error(
request,
_('You don\'t have privileges to add suggestions!')
)
# Stay on same entry
return False
if not request.user.is_authenticated:
# Spam check
if is_spam('\n'.join(form.cleaned_data['target']), request):
messages.error(
request,
_('Your suggestion has been identified as spam!')
)
return False
# Create the suggestion
result = Suggestion.objects.add(
unit,
join_plural(form.cleaned_data['target']),
request,
request.user.has_perm('suggestion.vote', unit)
)
if not result:
messages.error(request, _('Your suggestion already exists!'))
return result
开发者ID:nijel,项目名称:weblate,代码行数:33,代码来源:edit.py
示例5: translate
def translate(self, request, new_target, new_state, change_action=None,
propagate=True):
"""Store new translation of a unit."""
# Fetch current copy from database and lock it for update
self.old_unit = Unit.objects.select_for_update().get(pk=self.pk)
# Update unit and save it
if isinstance(new_target, six.string_types):
self.target = new_target
not_empty = bool(new_target)
else:
self.target = join_plural(new_target)
not_empty = bool(max(new_target))
# Newlines fixup
if 'dos-eol' in self.all_flags:
self.target = NEWLINES.sub('\r\n', self.target)
if not_empty:
self.state = new_state
else:
self.state = STATE_EMPTY
saved = self.save_backend(
request,
change_action=change_action,
propagate=propagate
)
if (propagate and request and
self.target != self.old_unit.target and
self.state >= STATE_TRANSLATED):
update_memory(request.user, self)
return saved
开发者ID:nijel,项目名称:weblate,代码行数:33,代码来源:unit.py
示例6: perform_suggestion
def perform_suggestion(unit, form, request):
"""Handle suggesion saving."""
if form.cleaned_data['target'][0] == '':
messages.error(request, _('Your suggestion is empty!'))
# Stay on same entry
return False
elif not request.user.has_perm('suggestion.add', unit.translation):
# Need privilege to add
messages.error(
request,
_('You don\'t have privileges to add suggestions!')
)
# Stay on same entry
return False
elif not request.user.is_authenticated:
# Spam check
if is_spam('\n'.join(form.cleaned_data['target']), request):
messages.error(
request,
_('Your suggestion has been identified as spam!')
)
return False
# Invite user to become translator if there is nobody else
# and the project is accepting translations
translation = unit.translation
if (not translation.component.suggestion_voting
or not translation.component.suggestion_autoaccept):
recent_changes = Change.objects.content(True).filter(
translation=translation,
).exclude(
user=None
)
if not recent_changes.exists():
messages.info(request, _(
'There is currently no active translator for this '
'translation, please consider becoming a translator '
'as your suggestion might otherwise remain unreviewed.'
))
messages.info(request, mark_safe(
'<a href="{0}">{1}</a>'.format(
escape(get_doc_url('user/translating')),
escape(_(
'See our documentation for more information '
'on translating using Weblate.'
)),
)
))
# Create the suggestion
result = Suggestion.objects.add(
unit,
join_plural(form.cleaned_data['target']),
request,
request.user.has_perm('suggestion.vote', unit)
)
if not result:
messages.error(request, _('Your suggestion already exists!'))
return result
开发者ID:dsnoeck,项目名称:weblate,代码行数:58,代码来源:edit.py
示例7: translate
def translate(self, request, new_target, new_fuzzy):
"""
Stores new translation of a unit.
"""
# Update unit and save it
self.target = join_plural(new_target)
self.fuzzy = new_fuzzy
saved = self.save_backend(request)
return saved
开发者ID:chervol,项目名称:weblate,代码行数:10,代码来源:unit.py
示例8: get_source
def get_source(self):
if self.template is None and self.mainunit.hasplural():
# Need to apply special magic for plurals here
# as there is no singlular/plural in the source string
source = self.unit.source
return join_plural([
source,
source.replace('(s)', 's'),
])
return super(TSUnit, self).get_source()
开发者ID:daleathan,项目名称:weblate,代码行数:10,代码来源:ttkit.py
示例9: translate
def translate(self, request, new_target, new_fuzzy, change_action=None,
propagate=True):
"""Store new translation of a unit."""
# Update unit and save it
self.target = join_plural(new_target)
self.fuzzy = new_fuzzy
saved = self.save_backend(
request,
change_action=change_action,
propagate=propagate
)
return saved
开发者ID:saily,项目名称:weblate,代码行数:13,代码来源:unit.py
示例10: translate
def translate(self, request, new_target, new_state, change_action=None,
propagate=True):
"""Store new translation of a unit."""
# Fetch current copy from database and lock it for update
self.old_unit = Unit.objects.select_for_update().get(pk=self.pk)
# Update unit and save it
if isinstance(new_target, six.string_types):
self.target = new_target
not_empty = bool(new_target)
else:
self.target = join_plural(new_target)
not_empty = bool(max(new_target))
if not_empty:
self.state = new_state
else:
self.state = STATE_EMPTY
saved = self.save_backend(
request,
change_action=change_action,
propagate=propagate
)
return saved
开发者ID:dsnoeck,项目名称:weblate,代码行数:24,代码来源:unit.py
示例11: update_from_unit
def update_from_unit(self, unit, pos, created):
"""Update Unit from ttkit unit."""
# Get unit attributes
location = unit.get_locations()
flags = unit.get_flags()
target = unit.get_target()
source = unit.get_source()
comment = unit.get_comments()
state = self.get_unit_state(unit, created)
previous_source = unit.get_previous_source()
content_hash = unit.get_content_hash()
# Monolingual files handling (without target change)
if unit.template is not None and target == self.target:
if source != self.source and state == STATE_TRANSLATED:
if self.previous_source == self.source and self.fuzzy:
# Source change was reverted
previous_source = ''
state = STATE_TRANSLATED
else:
# Store previous source and fuzzy flag for monolingual
if previous_source == '':
previous_source = self.source
state = STATE_FUZZY
else:
# We should keep calculated flags if translation was
# not changed outside
previous_source = self.previous_source
state = self.state
# Update checks on fuzzy update or on content change
same_content = (
target == self.target and source == self.source
)
same_state = (state == self.state and not created)
# Check if we actually need to change anything
# pylint: disable=too-many-boolean-expressions
if (not created and
location == self.location and
flags == self.flags and
same_content and same_state and
comment == self.comment and
pos == self.position and
content_hash == self.content_hash and
previous_source == self.previous_source):
return
# Ensure we track source string
source_info, source_created = Source.objects.get_or_create(
id_hash=self.id_hash,
component=self.translation.component
)
contentsum_changed = self.content_hash != content_hash
# Store updated values
self.position = pos
self.location = location
self.flags = flags
self.source = source
self.target = target
self.state = state
self.comment = comment
self.content_hash = content_hash
self.previous_source = previous_source
self.priority = source_info.priority
# Sanitize number of plurals
if self.is_plural():
self.target = join_plural(self.get_target_plurals())
if created:
unit_pre_create.send(sender=self.__class__, unit=self)
# Save into database
self.save(
force_insert=created,
backend=True,
same_content=same_content,
same_state=same_state,
)
# Create change object for new source string
if source_created:
Change.objects.create(
action=Change.ACTION_NEW_SOURCE,
unit=self,
)
if contentsum_changed:
self.update_has_failing_check(recurse=False)
self.update_has_comment()
self.update_has_suggestion()
开发者ID:dsnoeck,项目名称:weblate,代码行数:92,代码来源:unit.py
示例12: update_from_unit
def update_from_unit(self, unit, pos, created):
"""Update Unit from ttkit unit."""
component = self.translation.component
self.is_batch_update = True
# Get unit attributes
location = unit.locations
flags = unit.flags
target = unit.target
source = unit.source
context = unit.context
comment = unit.comments
state = self.get_unit_state(unit)
previous_source = unit.previous_source
content_hash = unit.content_hash
# Monolingual files handling (without target change)
if not created and unit.template is not None and target == self.target:
if source != self.source and state >= STATE_TRANSLATED:
if self.previous_source == self.source and self.fuzzy:
# Source change was reverted
previous_source = ''
state = STATE_TRANSLATED
else:
# Store previous source and fuzzy flag for monolingual
if previous_source == '':
previous_source = self.source
state = STATE_FUZZY
else:
# We should keep calculated flags if translation was
# not changed outside
previous_source = self.previous_source
state = self.state
# Update checks on fuzzy update or on content change
same_target = target == self.target
same_source = (source == self.source and context == self.context)
same_state = (state == self.state and flags == self.flags)
# Check if we actually need to change anything
# pylint: disable=too-many-boolean-expressions
if (location == self.location and
flags == self.flags and
same_source and same_target and same_state and
comment == self.comment and
pos == self.position and
content_hash == self.content_hash and
previous_source == self.previous_source):
return
# Ensure we track source string
source_info, source_created = component.get_source(self.id_hash)
self.__dict__['source_info'] = source_info
# Store updated values
self.position = pos
self.location = location
self.flags = flags
self.source = source
self.target = target
self.state = state
self.context = context
self.comment = comment
self.content_hash = content_hash
self.previous_source = previous_source
self.priority = source_info.priority
# Sanitize number of plurals
if self.is_plural():
self.target = join_plural(self.get_target_plurals())
if created:
unit_pre_create.send(sender=self.__class__, unit=self)
# Save into database
self.save(
force_insert=created,
same_content=same_source and same_target,
same_state=same_state,
)
# Create change object for new source string
if source_created:
Change.objects.create(
action=Change.ACTION_NEW_SOURCE,
unit=self,
)
# Track updated sources for source checks
if source_created or not same_source:
component.updated_sources[self.id_hash] = self
开发者ID:nijel,项目名称:weblate,代码行数:91,代码来源:unit.py
示例13: translate
def translate(request, project, subproject, lang):
obj = get_object_or_404(Translation, language__code = lang, subproject__slug = subproject, subproject__project__slug = project, enabled = True)
if obj.subproject.locked:
messages.error(request, _('This translation is currently locked for updates!'))
if request.user.is_authenticated():
profile = request.user.get_profile()
else:
profile = None
secondary = None
unit = None
rqtype, direction, pos, search_query, search_exact, search_source, search_target, search_context, search_url = parse_search_url(request)
# Any form submitted?
if request.method == 'POST':
form = TranslationForm(request.POST)
if form.is_valid() and not obj.subproject.locked:
# Check whether translation is not outdated
obj.check_sync()
try:
try:
unit = Unit.objects.get(checksum = form.cleaned_data['checksum'], translation = obj)
except Unit.MultipleObjectsReturned:
# Possible temporary inconsistency caused by ongoing update of repo,
# let's pretend everyting is okay
unit = Unit.objects.filter(checksum = form.cleaned_data['checksum'], translation = obj)[0]
if 'suggest' in request.POST:
# Handle suggesion saving
user = request.user
if isinstance(user, AnonymousUser):
user = None
if form.cleaned_data['target'] == len(form.cleaned_data['target']) * ['']:
messages.error(request, _('Your suggestion is empty!'))
# Stay on same entry
return HttpResponseRedirect('%s?type=%s&pos=%d&dir=stay%s' % (
obj.get_translate_url(),
rqtype,
pos,
search_url
))
Suggestion.objects.create(
target = join_plural(form.cleaned_data['target']),
checksum = unit.checksum,
language = unit.translation.language,
project = unit.translation.subproject.project,
user = user)
# Update suggestion stats
if profile is not None:
profile.suggested += 1
profile.save()
elif not request.user.is_authenticated():
# We accept translations only from authenticated
messages.error(request, _('You need to log in to be able to save translations!'))
elif not request.user.has_perm('trans.save_translation'):
# Need privilege to save
messages.error(request, _('You don\'t have privileges to save translations!'))
else:
# Remember old checks
oldchecks = set(unit.active_checks().values_list('check', flat = True))
# Update unit and save it
unit.target = join_plural(form.cleaned_data['target'])
unit.fuzzy = form.cleaned_data['fuzzy']
unit.save_backend(request)
# Update stats
profile.translated += 1
profile.save()
# Get new set of checks
newchecks = set(unit.active_checks().values_list('check', flat = True))
# Did we introduce any new failures?
if newchecks > oldchecks:
# Show message to user
messages.error(request, _('Some checks have failed on your translation!'))
# Stay on same entry
return HttpResponseRedirect('%s?type=%s&pos=%d&dir=stay%s' % (
obj.get_translate_url(),
rqtype,
pos,
search_url
))
# Redirect to next entry
return HttpResponseRedirect('%s?type=%s&pos=%d%s' % (
obj.get_translate_url(),
rqtype,
pos,
search_url
))
except Unit.DoesNotExist:
logger.error('message %s disappeared!', form.cleaned_data['checksum'])
messages.error(request, _('Message you wanted to translate is no longer available!'))
# Handle translation merging
if 'merge' in request.GET:
if not request.user.has_perm('trans.save_translation'):
# Need privilege to save
messages.error(request, _('You don\'t have privileges to save translations!'))
else:
#.........这里部分代码省略.........
开发者ID:aputtu,项目名称:weblate,代码行数:101,代码来源:views.py
注:本文中的weblate.trans.util.join_plural函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论