Skip to content

Commit

Permalink
Maintenance: Makes attachment matchwords easier to translate
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas committed Sep 20, 2024
1 parent 54193e2 commit 5a82c35
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 68 deletions.
22 changes: 12 additions & 10 deletions app/assets/javascripts/app/lib/app_post/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1050,16 +1050,18 @@ class App.Utils
tmp.find('blockquote').remove()
text = tmp.text()

matchwords = [__('Attachment'), __('attachment'), __('Attached'), __('attached'), __('Enclosed'), __('enclosed'), __('Enclosure'), __('enclosure')]
for word in matchwords
# en
attachmentTranslatedRegExp = new RegExp("\\W#{word}\\W", 'i')
return word if text.match(attachmentTranslatedRegExp)

# user locale
attachmentTranslated = App.i18n.translateContent(word)
attachmentTranslatedRegExp = new RegExp("\\W#{attachmentTranslated}\\W", 'i')
return attachmentTranslated if text.match(attachmentTranslatedRegExp)
matchwords = __('attachment,attached,enclosed,enclosure')

#en
for word in matchwords.split(',')
regexp = new RegExp("\\W#{word}\\W", 'i')
return word if text.match(regexp)

# user locale
for word in App.i18n.translateContent(matchwords).split(',')
regexp = new RegExp("\\W#{word}\\W", 'i')
return word if text.match(regexp)

false

# human readable file size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ import { domFrom } from '#shared/utils/dom.ts'

import { useConfirmation } from '../useConfirmation.ts'

const referenceMatchwords = [
__('Attachment'),
__('attachment'),
__('Attached'),
__('attached'),
__('Enclosed'),
__('enclosed'),
__('Enclosure'),
__('enclosure'),
]
const referenceMatchwords = __('attachment,attached,enclosed,enclosure')

const removeQuotingFromBody = (body: string) => {
const dom = domFrom(body)
Expand All @@ -31,14 +22,11 @@ const removeQuotingFromBody = (body: string) => {
const bodyAttachmentReferenceMatchwordExists = (body: string) => {
const cleanBody = removeQuotingFromBody(body)

return referenceMatchwords.some((word) => {
let findWord = new RegExp(word, 'i')

if (findWord.test(cleanBody)) return true

// Translate the word in the user locale.
findWord = new RegExp(i18n.t(word), 'i')
const matchwords = referenceMatchwords.split(',')
const translatedMatchwords = i18n.t(referenceMatchwords).split(',')

return matchwords.concat(translatedMatchwords).some((word) => {
const findWord = new RegExp(word, 'i')
return findWord.test(cleanBody)
})
}
Expand Down
44 changes: 6 additions & 38 deletions i18n/zammad.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1750,20 +1750,13 @@ msgstr ""
msgid "Attach files"
msgstr ""

#: app/assets/javascripts/app/lib/app_post/utils.coffee:1053
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:12
msgid "Attached"
msgstr ""

#: app/assets/javascripts/app/views/generic/attachments.jst.eco:4
#: app/views/knowledge_base/public/answers/show.html.erb:17
msgid "Attached Files"
msgstr ""

#: app/assets/javascripts/app/lib/app_post/utils.coffee:1053
#: app/frontend/apps/desktop/pages/ticket/views/TicketCreate.vue:202
#: app/frontend/apps/mobile/pages/ticket/views/TicketCreate.vue:316
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:10
#: app/frontend/shared/entities/ticket/composables/useTicketEditForm.ts:224
msgid "Attachment"
msgstr ""
Expand Down Expand Up @@ -4901,7 +4894,7 @@ msgstr ""
msgid "Did you know? You can help translating %s at:"
msgstr ""

#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:61
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:49
msgid "Did you plan to include attachments with this message?"
msgstr ""

Expand Down Expand Up @@ -5650,16 +5643,6 @@ msgstr ""
msgid "Enables users to create their own account via web interface. This setting is only effective if the password login is enabled."
msgstr ""

#: app/assets/javascripts/app/lib/app_post/utils.coffee:1053
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:14
msgid "Enclosed"
msgstr ""

#: app/assets/javascripts/app/lib/app_post/utils.coffee:1053
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:16
msgid "Enclosure"
msgstr ""

#: app/assets/javascripts/app/views/agent_ticket_create.jst.eco:41
#: app/assets/javascripts/app/views/ticket_zoom/article_new.jst.eco:77
#: app/frontend/apps/desktop/components/Form/fields/FieldSecurity/FieldSecurityInput.vue:50
Expand Down Expand Up @@ -9866,7 +9849,7 @@ msgstr ""
msgid "No, just close the ticket"
msgstr ""

#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:64
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:52
msgid "No, thanks"
msgstr ""

Expand Down Expand Up @@ -17259,7 +17242,7 @@ msgstr ""
msgid "Yes"
msgstr ""

#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:63
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:51
msgid "Yes, add attachments now"
msgstr ""

Expand Down Expand Up @@ -17778,13 +17761,8 @@ msgid "at least one letter is required"
msgstr ""

#: app/assets/javascripts/app/lib/app_post/utils.coffee:1053
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:13
msgid "attached"
msgstr ""

#: app/assets/javascripts/app/lib/app_post/utils.coffee:1053
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:11
msgid "attachment"
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:9
msgid "attachment,attached,enclosed,enclosure"
msgstr ""

#: app/models/object_manager/attribute.rb:580
Expand Down Expand Up @@ -18093,16 +18071,6 @@ msgstr ""
msgid "email sent to '%s'"
msgstr ""

#: app/assets/javascripts/app/lib/app_post/utils.coffee:1053
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:15
msgid "enclosed"
msgstr ""

#: app/assets/javascripts/app/lib/app_post/utils.coffee:1053
#: app/frontend/shared/composables/form/useCheckBodyAttachmentReference.ts:17
msgid "enclosure"
msgstr ""

#: app/assets/javascripts/app/controllers/_ui_element/core_workflow_condition.coffee:186
msgid "ends with"
msgstr ""
Expand Down Expand Up @@ -18314,7 +18282,7 @@ msgid "in process"
msgstr ""

#: app/assets/javascripts/app/controllers/_ui_element/active.coffee:5
#: app/assets/javascripts/app/lib/app_post/utils.coffee:1426
#: app/assets/javascripts/app/lib/app_post/utils.coffee:1428
#: app/assets/javascripts/app/models/webhook.coffee:34
#: app/assets/javascripts/app/views/generic/object_search/item_object.jst.eco:16
#: app/assets/javascripts/app/views/generic/object_search/item_organization.jst.eco:4
Expand Down
6 changes: 3 additions & 3 deletions public/assets/tests/qunit/html_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1349,12 +1349,12 @@ QUnit.test("check check attachment reference", assert => {
assert.equal(verify, result)

message = 'some attachment for you'
result = 'Attachment'
result = 'attachment'
verify = App.Utils.checkAttachmentReference(message)
assert.equal(verify, result)

message = 'your attachment.'
result = 'Attachment'
result = 'attachment'
verify = App.Utils.checkAttachmentReference(message)
assert.equal(verify, result)

Expand All @@ -1374,7 +1374,7 @@ QUnit.test("check check attachment reference", assert => {
assert.equal(verify, result)

message = 'As enclosed you will find.'
result = 'Enclosed'
result = 'enclosed'
verify = App.Utils.checkAttachmentReference(message)
assert.equal(verify, result)

Expand Down

0 comments on commit 5a82c35

Please sign in to comment.