Created page for bundle translations.

Minor changes.
This commit is contained in:
Prominence 2016-06-24 14:39:19 +03:00
parent e36e2bdff5
commit 675eb1d055
9 changed files with 81 additions and 33 deletions

View File

@ -9,8 +9,19 @@ class TranslationsOverviewController {
render view: 'index', model: [bundles: bundleService.getBundles()] 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]
} }
} }

View File

@ -1 +1,5 @@
plugin.translations.overview.page.title = Translations overview 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

View File

@ -1 +1,5 @@
plugin.translations.overview.page.title = Translations overview 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

View File

@ -1 +1,5 @@
plugin.translations.overview.page.title = Translations overview 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

View File

@ -1 +1,5 @@
plugin.translations.overview.page.title = Обзор переводов plugin.translations.overview.index.page.title = Обзор переводов
plugin.translations.overview.show.page.title = Бандл {0}
plugin.translations.totalRecords = Всего: {0} записей
plugin.translations.totalBundles = Всего: {0} бандлов

View File

@ -4,7 +4,8 @@ class BundleService {
private HashSet<Bundle> cachedBundles private HashSet<Bundle> cachedBundles
private static final defaultFolder = "i18n" private static final String DEFAULT_FOLDER = "i18n"
private static final String DEFAULT_EXTENSION = '.properties'
HashSet<Bundle> getBundles(boolean noCache = false) { HashSet<Bundle> getBundles(boolean noCache = false) {
if (!cachedBundles || noCache) { if (!cachedBundles || noCache) {
@ -13,11 +14,18 @@ class BundleService {
return cachedBundles return cachedBundles
} }
Bundle findBundleByName(String name) {
getBundles().find { Bundle bundle ->
bundle.name == name
}
}
private Map<String, Bundle> searchForBundles() { private Map<String, Bundle> searchForBundles() {
Map<String, Bundle> result = new HashMap<>() Map<String, Bundle> result = new HashMap<>()
new File('.').eachFileRecurse() { File file -> new File('.').eachFileRecurse() { File file ->
if(file.name.endsWith('.properties')) { if(file.name.endsWith(DEFAULT_EXTENSION)) {
if (isTranslationProperty(file)) { if (isTranslationProperty(file)) {
String bundleName = getBundleName(file.name) String bundleName = getBundleName(file.name)
@ -34,7 +42,7 @@ class BundleService {
} }
private boolean isTranslationProperty(File file) { private boolean isTranslationProperty(File file) {
return file.parent.contains(defaultFolder) return file.parent.contains(DEFAULT_FOLDER)
} }
private String getFileNameWithoutExtension(String filename) { private String getFileNameWithoutExtension(String filename) {

View File

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta name="layout" content="main"/> <meta name="layout" content="main"/>
<title><g:message code="plugin.translations.overview.page.title" /></title> <title><g:message code="plugin.translations.overview.index.page.title" /></title>
<r:require modules="bootstrap"/> <r:require modules="bootstrap"/>
</head> </head>
@ -10,23 +10,13 @@
<g:if test="${bundles}"> <g:if test="${bundles}">
<ol> <ol>
<g:each in="${bundles}" var="bundle"> <g:each in="${bundles}" var="bundle">
<li>${bundle.name}<li> <li><g:link action="show" params="${[bundleName: bundle.name]}" >${bundle.name}</g:link></li>
<ul>
<g:each in="${bundle.propertiesList}" var="properties">
<li>${properties.name}</li>
${properties.text.eachLine { line ->
print('----------> ' + line + '<br/>')
}}
</g:each>
</ul>
</g:each> </g:each>
</ol> </ol>
</g:if> </g:if>
<g:else> <g:else>
There is no bundles! There is no bundles!
</g:else> </g:else>
<button class="btn btn-default" type="button"> <g:message code="plugin.translations.totalBundles" args="${[bundles.size()]}"/>
Test bootstrap button
</button>
</body> </body>
</html> </html>

View File

@ -0,0 +1,34 @@
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta name="layout" content="main"/>
<title><g:message code="plugin.translations.overview.show.page.title" args="${[bundle.name]}" /></title>
<r:require modules="bootstrap"/>
</head>
<body>
<h1><g:message code="plugin.translations.overview.show.page.title" args="${[bundle.name]}" /></h1>
<br/>
<table>
<thead>
<tr>
<g:each in="${bundle.propertiesList}" var="propertyFile">
<th>${propertyFile.name}</th>
</g:each>
</tr>
</thead>
<tbody>
<tr>
<g:each in="${bundle.propertiesList}" var="propertyFile">
<td>${propertyFile.text}</td>
</g:each>
</tr>
<tr>
<g:each in="${bundle.propertiesList}" var="propertyFile">
<td><g:message code="plugin.translations.totalRecords" args="${propertyFile.readLines().size()}"/></td>
</g:each>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -1,11 +0,0 @@
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta name="layout" content="main"/>
<title>bundles</title>
</head>
<body>
</body>
</html>