From 675eb1d055b3fdc96b5ed8d5c360d44131c3ad0c Mon Sep 17 00:00:00 2001 From: Prominence Date: Fri, 24 Jun 2016 14:39:19 +0300 Subject: [PATCH] Created page for bundle translations. Minor changes. --- .../TranslationsOverviewController.groovy | 15 ++++++-- grails-app/i18n/messages.properties | 6 +++- grails-app/i18n/messages_de.properties | 6 +++- grails-app/i18n/messages_en.properties | 6 +++- grails-app/i18n/messages_ru.properties | 6 +++- .../translations/BundleService.groovy | 14 ++++++-- .../views/translationsOverview/index.gsp | 16 ++------- .../views/translationsOverview/show.gsp | 34 +++++++++++++++++++ .../translationsOverview/showBundles.gsp | 11 ------ 9 files changed, 81 insertions(+), 33 deletions(-) create mode 100644 grails-app/views/translationsOverview/show.gsp delete mode 100644 grails-app/views/translationsOverview/showBundles.gsp diff --git a/grails-app/controllers/by/prominence/translations/TranslationsOverviewController.groovy b/grails-app/controllers/by/prominence/translations/TranslationsOverviewController.groovy index ce3fccc..2e60e61 100644 --- a/grails-app/controllers/by/prominence/translations/TranslationsOverviewController.groovy +++ b/grails-app/controllers/by/prominence/translations/TranslationsOverviewController.groovy @@ -9,8 +9,19 @@ class TranslationsOverviewController { render view: 'index', model: [bundles: bundleService.getBundles()] } - def showBundles() { + def show() { - render view: 'showBundles', model: [bundles: bundleService.getBundles()] + if (!params.bundleName) { + // render error + } + + Bundle bundle = bundleService.findBundleByName(params.bundleName as String) + + if (!bundle) { + // render error + } + + render view: 'show', model: [bundle: bundle] } + } diff --git a/grails-app/i18n/messages.properties b/grails-app/i18n/messages.properties index 62b8f7d..74c0482 100644 --- a/grails-app/i18n/messages.properties +++ b/grails-app/i18n/messages.properties @@ -1 +1,5 @@ -plugin.translations.overview.page.title = Translations overview \ No newline at end of file +plugin.translations.overview.index.page.title = Translations overview +plugin.translations.overview.show.page.title = Bundle {0} + +plugin.translations.totalRecords = Total: {0} records +plugin.translations.totalBundles = Total: {0} bundles \ No newline at end of file diff --git a/grails-app/i18n/messages_de.properties b/grails-app/i18n/messages_de.properties index 62b8f7d..74c0482 100644 --- a/grails-app/i18n/messages_de.properties +++ b/grails-app/i18n/messages_de.properties @@ -1 +1,5 @@ -plugin.translations.overview.page.title = Translations overview \ No newline at end of file +plugin.translations.overview.index.page.title = Translations overview +plugin.translations.overview.show.page.title = Bundle {0} + +plugin.translations.totalRecords = Total: {0} records +plugin.translations.totalBundles = Total: {0} bundles \ No newline at end of file diff --git a/grails-app/i18n/messages_en.properties b/grails-app/i18n/messages_en.properties index 62b8f7d..74c0482 100644 --- a/grails-app/i18n/messages_en.properties +++ b/grails-app/i18n/messages_en.properties @@ -1 +1,5 @@ -plugin.translations.overview.page.title = Translations overview \ No newline at end of file +plugin.translations.overview.index.page.title = Translations overview +plugin.translations.overview.show.page.title = Bundle {0} + +plugin.translations.totalRecords = Total: {0} records +plugin.translations.totalBundles = Total: {0} bundles \ No newline at end of file diff --git a/grails-app/i18n/messages_ru.properties b/grails-app/i18n/messages_ru.properties index e098f2c..4d0d61a 100644 --- a/grails-app/i18n/messages_ru.properties +++ b/grails-app/i18n/messages_ru.properties @@ -1 +1,5 @@ -plugin.translations.overview.page.title = Обзор переводов \ No newline at end of file +plugin.translations.overview.index.page.title = Обзор переводов +plugin.translations.overview.show.page.title = Бандл {0} + +plugin.translations.totalRecords = Всего: {0} записей +plugin.translations.totalBundles = Всего: {0} бандлов \ No newline at end of file diff --git a/grails-app/services/by/prominence/translations/BundleService.groovy b/grails-app/services/by/prominence/translations/BundleService.groovy index 0ea1795..1e5ba4c 100644 --- a/grails-app/services/by/prominence/translations/BundleService.groovy +++ b/grails-app/services/by/prominence/translations/BundleService.groovy @@ -4,7 +4,8 @@ class BundleService { private HashSet cachedBundles - private static final defaultFolder = "i18n" + private static final String DEFAULT_FOLDER = "i18n" + private static final String DEFAULT_EXTENSION = '.properties' HashSet getBundles(boolean noCache = false) { if (!cachedBundles || noCache) { @@ -13,11 +14,18 @@ class BundleService { return cachedBundles } + Bundle findBundleByName(String name) { + + getBundles().find { Bundle bundle -> + bundle.name == name + } + } + private Map searchForBundles() { Map result = new HashMap<>() new File('.').eachFileRecurse() { File file -> - if(file.name.endsWith('.properties')) { + if(file.name.endsWith(DEFAULT_EXTENSION)) { if (isTranslationProperty(file)) { String bundleName = getBundleName(file.name) @@ -34,7 +42,7 @@ class BundleService { } private boolean isTranslationProperty(File file) { - return file.parent.contains(defaultFolder) + return file.parent.contains(DEFAULT_FOLDER) } private String getFileNameWithoutExtension(String filename) { diff --git a/grails-app/views/translationsOverview/index.gsp b/grails-app/views/translationsOverview/index.gsp index a3e0ff4..8dbd062 100644 --- a/grails-app/views/translationsOverview/index.gsp +++ b/grails-app/views/translationsOverview/index.gsp @@ -2,7 +2,7 @@ - <g:message code="plugin.translations.overview.page.title" /> + <g:message code="plugin.translations.overview.index.page.title" /> @@ -10,23 +10,13 @@
    -
  1. ${bundle.name}
  2. -
      - -
    • ${properties.name}
    • - ${properties.text.eachLine { line -> - print('----------> ' + line + '
      ') - }} -
      -
    +
  3. ${bundle.name}
There is no bundles! - + \ No newline at end of file diff --git a/grails-app/views/translationsOverview/show.gsp b/grails-app/views/translationsOverview/show.gsp new file mode 100644 index 0000000..7b51458 --- /dev/null +++ b/grails-app/views/translationsOverview/show.gsp @@ -0,0 +1,34 @@ +<%@ page contentType="text/html;charset=UTF-8" %> + + + + <g:message code="plugin.translations.overview.show.page.title" args="${[bundle.name]}" /> + + + + +

+
+ + + + + + + + + + + + + + + + + + + + +
${propertyFile.name}
${propertyFile.text}
+ + \ No newline at end of file diff --git a/grails-app/views/translationsOverview/showBundles.gsp b/grails-app/views/translationsOverview/showBundles.gsp deleted file mode 100644 index 9355f03..0000000 --- a/grails-app/views/translationsOverview/showBundles.gsp +++ /dev/null @@ -1,11 +0,0 @@ -<%@ page contentType="text/html;charset=UTF-8" %> - - - - bundles - - - - - - \ No newline at end of file