mirror of
https://github.com/Prominence/grails-translations-plugin.git
synced 2026-01-09 19:06:41 +03:00
Changed domain models. Added page for changing translations (just a model).
Added tag lib.
This commit is contained in:
parent
f1eda4f146
commit
bde8905bfa
@ -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() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,9 +3,9 @@ package by.prominence.translations
|
||||
class Bundle {
|
||||
|
||||
String name
|
||||
List<File> propertiesList = new ArrayList<>()
|
||||
List<Language> languages = new ArrayList<>()
|
||||
|
||||
public void addPropertyFile(File file) {
|
||||
propertiesList.add(file)
|
||||
public void addLanguage(Language lang) {
|
||||
languages.add(lang)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
package by.prominence.translations
|
||||
|
||||
class BundleProperties {
|
||||
|
||||
Bundle bundle
|
||||
Properties properties
|
||||
|
||||
}
|
||||
10
grails-app/domain/by/prominence/translations/Language.groovy
Normal file
10
grails-app/domain/by/prominence/translations/Language.groovy
Normal file
@ -0,0 +1,10 @@
|
||||
package by.prominence.translations
|
||||
|
||||
class Language {
|
||||
|
||||
Map translations = [:]
|
||||
Bundle bundle
|
||||
String languageTag
|
||||
|
||||
File languageFile
|
||||
}
|
||||
@ -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 <b>{0}</b>.
|
||||
|
||||
plugin.translations.action.save = Save
|
||||
@ -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 <b>{0}</b>.
|
||||
|
||||
plugin.translations.action.save = Save
|
||||
@ -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 <b>{0}</b>.
|
||||
|
||||
plugin.translations.action.save = Save
|
||||
@ -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 = Бандл с именем <b>{0}</b> не найден.
|
||||
|
||||
plugin.translations.action.save = Сохранить
|
||||
@ -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<Bundle> 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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
19
grails-app/views/translationsOverview/edit.gsp
Normal file
19
grails-app/views/translationsOverview/edit.gsp
Normal file
@ -0,0 +1,19 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" %>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="layout" content="main"/>
|
||||
<title><g:message code="plugin.translations.overview.edit.page.title" args="${[bundle.name]}"/></title>
|
||||
<r:require modules="bootstrap"/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<g:each in="${bundle.languages}" var="language">
|
||||
<g:render template="templates/language" model="${[language: language]}" />
|
||||
<br />
|
||||
</g:each>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -12,20 +12,22 @@
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<g:each in="${bundle.propertiesList}" var="propertyFile">
|
||||
<th>${propertyFile.name}</th>
|
||||
<g:each in="${bundle.languages}" var="language">
|
||||
<th>${language.languageTag.toUpperCase()}</th>
|
||||
</g:each>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<g:each in="${bundle.propertiesList}" var="propertyFile">
|
||||
<td>${propertyFile.text}</td>
|
||||
<g:each in="${bundle.languages}" var="language">
|
||||
<td>${language.translations.each {key, value ->
|
||||
print (key + '=' + value)
|
||||
}}</td>
|
||||
</g:each>
|
||||
</tr>
|
||||
<tr>
|
||||
<g:each in="${bundle.propertiesList}" var="propertyFile">
|
||||
<td><g:message code="plugin.translations.totalRecords" args="${propertyFile.readLines()?.size() ?: '0'}"/></td>
|
||||
<g:each in="${bundle.languages}" var="language">
|
||||
<td><g:message code="plugin.translations.totalRecords" args="${language.translations.size() ?: '0'}"/></td>
|
||||
</g:each>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
<g:form action="saveFile" name="${language.languageTag}">
|
||||
<h3>${language.languageTag.toUpperCase()}</h3>
|
||||
<g:each in="${language.translations}" var="translation">
|
||||
<g:set var="key" value="${ts.propertyKey(property: translation)}"/>
|
||||
<label>${key}</label> <g:textField name="${key}" value="${ts.propertyValue(property: translation)}" />
|
||||
<br/>
|
||||
</g:each>
|
||||
<g:submitButton name="save" class="btn btn-primary" value="${g.message(code: 'plugin.translations.action.save')}"/>
|
||||
</g:form>
|
||||
Loading…
x
Reference in New Issue
Block a user