Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2019-04-15 15:31:55 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2019-04-15 15:45:28 +0300
commit3d88c067992b62c7222453b149ec9d3c4c43103c (patch)
tree99f6096a5d2779a85edab9cefc05499a4803dcd6 /src
parent4a55889ed7cdb7362e5e79eff07f54855451848f (diff)
Translate folder names on the client-side
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'src')
-rw-r--r--src/components/Navigation.vue4
-rw-r--r--src/l10n/MailboxTranslator.js70
-rw-r--r--src/store/index.js1
-rw-r--r--src/tests/setup.js8
-rw-r--r--src/tests/unit/l10n/MailboxTranslator.spec.js46
5 files changed, 127 insertions, 2 deletions
diff --git a/src/components/Navigation.vue b/src/components/Navigation.vue
index a5b791942..9a9b200c8 100644
--- a/src/components/Navigation.vue
+++ b/src/components/Navigation.vue
@@ -42,7 +42,6 @@
<script>
import {translate as t} from 'nextcloud-server/dist/l10n'
import {
- AppContent,
AppNavigation,
AppNavigationItem,
AppNavigationNew,
@@ -51,6 +50,7 @@ import {
} from 'nextcloud-vue'
import {calculateAccountColor} from '../util/AccountColor'
+import {translate as translateMailboxName} from '../l10n/MailboxTranslator'
const SHOW_COLLAPSED = Object.seal(['inbox', 'flagged', 'drafts', 'sent'])
@@ -118,7 +118,7 @@ export default {
return {
id: 'account' + account.id + '_' + folder.id,
key: 'account' + account.id + '_' + folder.id,
- text: folder.name,
+ text: translateMailboxName(folder),
icon: 'icon-' + icon,
router: {
name: 'folder',
diff --git a/src/l10n/MailboxTranslator.js b/src/l10n/MailboxTranslator.js
new file mode 100644
index 000000000..36073d165
--- /dev/null
+++ b/src/l10n/MailboxTranslator.js
@@ -0,0 +1,70 @@
+/*
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import {translate as t} from 'nextcloud-server/dist/l10n'
+
+const translateSpecial = folder => {
+ if (folder.specialUse.includes('all')) {
+ // TRANSLATORS: translated mail box name
+ return t('mail', 'All')
+ }
+ if (folder.specialUse.includes('archive')) {
+ // TRANSLATORS: translated mail box name
+ return t('mail', 'Archive')
+ }
+ if (folder.specialUse.includes('drafts')) {
+ // TRANSLATORS: translated mail box name
+ return t('mail', 'Drafts')
+ }
+ if (folder.specialUse.includes('flagged')) {
+ // TRANSLATORS: translated mail box name
+ return t('mail', 'Favorites')
+ }
+ if (folder.specialUse.includes('inbox')) {
+ // TRANSLATORS: translated mail box name
+ return t('mail', 'Inbox')
+ }
+ if (folder.specialUse.includes('junk')) {
+ // TRANSLATORS: translated mail box name
+ return t('mail', 'Junk')
+ }
+ if (folder.specialUse.includes('sent')) {
+ // TRANSLATORS: translated mail box name
+ return t('mail', 'Sent')
+ }
+ if (folder.specialUse.includes('trash')) {
+ // TRANSLATORS: translated mail box name
+ return t('mail', 'Trash')
+ }
+ throw new Error(`unknown special use ${folder.specialUse}`)
+}
+
+export const translate = folder => {
+ if (folder.specialUse.length > 0) {
+ try {
+ return translateSpecial(folder)
+ } catch (e) {
+ console.error(e)
+ return folder.id
+ }
+ }
+ return folder.id
+}
diff --git a/src/store/index.js b/src/store/index.js
index f2a1cf429..21618bc05 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -95,6 +95,7 @@ export default new Vuex.Store({
id: UNIFIED_INBOX_ID,
accountId: 0,
isUnified: true,
+ specialUse: ['inbox'],
specialRole: 'inbox',
name: t('mail', 'All inboxes'), // TODO,
unread: 0,
diff --git a/src/tests/setup.js b/src/tests/setup.js
index b2ca1d5c1..e3db9cef8 100644
--- a/src/tests/setup.js
+++ b/src/tests/setup.js
@@ -33,4 +33,12 @@ global.SVGElement = global.Element
global.OC = {
getLocale: () => 'en',
+ L10N: {
+ translate: (app, string) => {
+ if (app !== 'mail') {
+ throw new Error('tried to translate a string for an app other than Mail')
+ }
+ return string
+ },
+ },
}
diff --git a/src/tests/unit/l10n/MailboxTranslator.spec.js b/src/tests/unit/l10n/MailboxTranslator.spec.js
new file mode 100644
index 000000000..bd6133520
--- /dev/null
+++ b/src/tests/unit/l10n/MailboxTranslator.spec.js
@@ -0,0 +1,46 @@
+/*
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import {translate} from '../../../l10n/MailboxTranslator'
+
+describe('MailboxTranslator', () => {
+ it('translates the inbox', () => {
+ const folder = {
+ id: 'INBOX',
+ specialUse: ['inbox'],
+ }
+
+ const name = translate(folder)
+
+ expect(name).to.equal('Inbox')
+ })
+
+ it('does not translate an arbitrary mailbox', () => {
+ const folder = {
+ id: 'Newsletters',
+ specialUse: [],
+ }
+
+ const name = translate(folder)
+
+ expect(name).to.equal('Newsletters')
+ })
+})