diff --git a/grails-app/controllers/by/prominence/translations/TranslationsOverviewController.groovy b/grails-app/controllers/by/prominence/translations/TranslationsOverviewController.groovy index 8e2cf46..69fa58b 100644 --- a/grails-app/controllers/by/prominence/translations/TranslationsOverviewController.groovy +++ b/grails-app/controllers/by/prominence/translations/TranslationsOverviewController.groovy @@ -26,4 +26,25 @@ class TranslationsOverviewController { render view: 'show', model: [bundle: bundle] } + def edit() { + + if (!params.bundleName) { + redirect action: 'index' + return + } + + Bundle bundle = bundleService.findBundleByName(params.bundleName as String) + + if (!bundle) { + render view: 'index', model: [message: g.message(code: 'plugin.translations.error.bundleNotFound', args: [params.bundleName as String])] + return + } + + render view: 'edit', model: [bundle: bundle] + } + + def saveFile() { + + } + } diff --git a/grails-app/domain/by/prominence/translations/Bundle.groovy b/grails-app/domain/by/prominence/translations/Bundle.groovy index dd07da3..a69ea73 100644 --- a/grails-app/domain/by/prominence/translations/Bundle.groovy +++ b/grails-app/domain/by/prominence/translations/Bundle.groovy @@ -3,9 +3,9 @@ package by.prominence.translations class Bundle { String name - List propertiesList = new ArrayList<>() + List languages = new ArrayList<>() - public void addPropertyFile(File file) { - propertiesList.add(file) + public void addLanguage(Language lang) { + languages.add(lang) } } diff --git a/grails-app/domain/by/prominence/translations/BundleProperties.groovy b/grails-app/domain/by/prominence/translations/BundleProperties.groovy deleted file mode 100644 index a1a3500..0000000 --- a/grails-app/domain/by/prominence/translations/BundleProperties.groovy +++ /dev/null @@ -1,8 +0,0 @@ -package by.prominence.translations - -class BundleProperties { - - Bundle bundle - Properties properties - -} diff --git a/grails-app/domain/by/prominence/translations/Language.groovy b/grails-app/domain/by/prominence/translations/Language.groovy new file mode 100644 index 0000000..32af271 --- /dev/null +++ b/grails-app/domain/by/prominence/translations/Language.groovy @@ -0,0 +1,10 @@ +package by.prominence.translations + +class Language { + + Map translations = [:] + Bundle bundle + String languageTag + + File languageFile +} diff --git a/grails-app/i18n/messages.properties b/grails-app/i18n/messages.properties index 1be523f..2be0283 100644 --- a/grails-app/i18n/messages.properties +++ b/grails-app/i18n/messages.properties @@ -1,7 +1,10 @@ plugin.translations.overview.index.page.title = Translations overview plugin.translations.overview.show.page.title = Bundle {0} +plugin.translations.overview.edit.page.title = Edit {0} bundle plugin.translations.totalRecords = Total: {0} records plugin.translations.totalBundles = Total: {0} bundles -plugin.translations.error.bundleNotFound = Cannot find bundle {0}. \ No newline at end of file +plugin.translations.error.bundleNotFound = Cannot find bundle {0}. + +plugin.translations.action.save = Save \ No newline at end of file diff --git a/grails-app/i18n/messages_de.properties b/grails-app/i18n/messages_de.properties index 1be523f..2be0283 100644 --- a/grails-app/i18n/messages_de.properties +++ b/grails-app/i18n/messages_de.properties @@ -1,7 +1,10 @@ plugin.translations.overview.index.page.title = Translations overview plugin.translations.overview.show.page.title = Bundle {0} +plugin.translations.overview.edit.page.title = Edit {0} bundle plugin.translations.totalRecords = Total: {0} records plugin.translations.totalBundles = Total: {0} bundles -plugin.translations.error.bundleNotFound = Cannot find bundle {0}. \ No newline at end of file +plugin.translations.error.bundleNotFound = Cannot find bundle {0}. + +plugin.translations.action.save = Save \ No newline at end of file diff --git a/grails-app/i18n/messages_en.properties b/grails-app/i18n/messages_en.properties index 1be523f..2be0283 100644 --- a/grails-app/i18n/messages_en.properties +++ b/grails-app/i18n/messages_en.properties @@ -1,7 +1,10 @@ plugin.translations.overview.index.page.title = Translations overview plugin.translations.overview.show.page.title = Bundle {0} +plugin.translations.overview.edit.page.title = Edit {0} bundle plugin.translations.totalRecords = Total: {0} records plugin.translations.totalBundles = Total: {0} bundles -plugin.translations.error.bundleNotFound = Cannot find bundle {0}. \ No newline at end of file +plugin.translations.error.bundleNotFound = Cannot find bundle {0}. + +plugin.translations.action.save = Save \ No newline at end of file diff --git a/grails-app/i18n/messages_ru.properties b/grails-app/i18n/messages_ru.properties index 217a99c..f3bff93 100644 --- a/grails-app/i18n/messages_ru.properties +++ b/grails-app/i18n/messages_ru.properties @@ -1,7 +1,10 @@ plugin.translations.overview.index.page.title = Обзор переводов plugin.translations.overview.show.page.title = Бандл {0} +plugin.translations.overview.edit.page.title = Редактирование бандла {0} plugin.translations.totalRecords = Всего: {0} записей plugin.translations.totalBundles = Всего: {0} бандлов -plugin.translations.error.bundleNotFound = Бандл с именем {0} не найден. \ No newline at end of file +plugin.translations.error.bundleNotFound = Бандл с именем {0} не найден. + +plugin.translations.action.save = Сохранить \ 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 1e5ba4c..3f01891 100644 --- a/grails-app/services/by/prominence/translations/BundleService.groovy +++ b/grails-app/services/by/prominence/translations/BundleService.groovy @@ -6,6 +6,7 @@ class BundleService { private static final String DEFAULT_FOLDER = "i18n" private static final String DEFAULT_EXTENSION = '.properties' + private static final String STANDARD_LANGUAGE_TAG = 'standard' HashSet getBundles(boolean noCache = false) { if (!cachedBundles || noCache) { @@ -33,7 +34,9 @@ class BundleService { Bundle bundle = new Bundle(name: bundleName) result.put(bundleName, bundle) } - result.get(bundleName).addPropertyFile(file) + Language lang = createLanguage(file) + lang.bundle = result.get(bundleName) + result.get(bundleName).addLanguage(lang) } } } @@ -42,7 +45,7 @@ class BundleService { } private boolean isTranslationProperty(File file) { - return file.parent.contains(DEFAULT_FOLDER) + return file.parent.contains(DEFAULT_FOLDER) //TODO: is it necessary to use parent? } private String getFileNameWithoutExtension(String filename) { @@ -54,4 +57,35 @@ class BundleService { getFileNameWithoutExtension(filename) : filename.substring(0, filename.indexOf('_')) } + private Language createLanguage(File file) { + + Language lang = new Language() + lang.languageFile = file + + String filename = getFileNameWithoutExtension(file.name) + + // setting language tag + if (filename.contains('_')) { + String tag = filename.substring(filename.indexOf('_') + 1) + lang.languageTag = tag + } else { + lang.languageTag = STANDARD_LANGUAGE_TAG + } + + file.text.readLines().each { String line -> + if (!line.equals('')) { + lang.translations.put(getKey(line), getValue(line)) + } + } + + return lang + } + + private String getKey(String line) { + return line.substring(0, line.indexOf('=')) + } + + private String getValue(String line) { + return line.substring(line.indexOf('=') + 1) + } } diff --git a/grails-app/taglib/by/prominence/translations/PropertyTagLib.groovy b/grails-app/taglib/by/prominence/translations/PropertyTagLib.groovy new file mode 100644 index 0000000..3d06c74 --- /dev/null +++ b/grails-app/taglib/by/prominence/translations/PropertyTagLib.groovy @@ -0,0 +1,24 @@ +package by.prominence.translations + +class PropertyTagLib { + + static namespace = "ts" + + def propertyKey = { attrs, body -> + + assert attrs.property + + String property = attrs.property as String + + out << property.substring(0, property.indexOf('=')).trim() + } + + def propertyValue = {attrs, body -> + + assert attrs.property + + String property = attrs.property as String + + out << property.substring(property.indexOf('=') + 1).trim() + } +} diff --git a/grails-app/views/translationsOverview/edit.gsp b/grails-app/views/translationsOverview/edit.gsp new file mode 100644 index 0000000..7d5db2a --- /dev/null +++ b/grails-app/views/translationsOverview/edit.gsp @@ -0,0 +1,19 @@ +<%@ page contentType="text/html;charset=UTF-8" %> + + + + <g:message code="plugin.translations.overview.edit.page.title" args="${[bundle.name]}"/> + + + + +
+
+ + +
+
+
+
+ + \ No newline at end of file diff --git a/grails-app/views/translationsOverview/show.gsp b/grails-app/views/translationsOverview/show.gsp index 1f23ac7..004b2ef 100644 --- a/grails-app/views/translationsOverview/show.gsp +++ b/grails-app/views/translationsOverview/show.gsp @@ -12,20 +12,22 @@ - - + + - - + + - - + + diff --git a/grails-app/views/translationsOverview/templates/_language.gsp b/grails-app/views/translationsOverview/templates/_language.gsp new file mode 100644 index 0000000..63d4761 --- /dev/null +++ b/grails-app/views/translationsOverview/templates/_language.gsp @@ -0,0 +1,9 @@ + +

${language.languageTag.toUpperCase()}

+ + + +
+
+ +
\ No newline at end of file
${propertyFile.name}${language.languageTag.toUpperCase()}
${propertyFile.text}${language.translations.each {key, value -> + print (key + '=' + value) + }}