mirror of
https://github.com/Prominence/grails-translations-plugin.git
synced 2026-01-08 10:26:46 +03:00
Implemented export functionality. Minor layout fixes.
This commit is contained in:
parent
34048f9525
commit
98dfa730ce
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,4 +3,5 @@
|
||||
target
|
||||
.idea
|
||||
*.zip
|
||||
*.iml
|
||||
.slcache
|
||||
@ -1,5 +1,8 @@
|
||||
package by.prominence.translations
|
||||
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
class TranslationsManagementController {
|
||||
|
||||
def bundleService
|
||||
@ -54,4 +57,39 @@ class TranslationsManagementController {
|
||||
redirect action: 'index'
|
||||
}
|
||||
|
||||
def export() {
|
||||
|
||||
if (params.bundleName) {
|
||||
|
||||
Bundle bundle = bundleService.findBundleByName(params.bundleName)
|
||||
|
||||
if (params.langTag) {
|
||||
File exportFile = bundle.languages.find { lang ->
|
||||
lang.languageTag == params.langTag
|
||||
}?.languageFile
|
||||
|
||||
if (exportFile && exportFile.exists()) {
|
||||
response.setHeader "Content-disposition", "attachment; filename=${exportFile.name}"
|
||||
response.contentType = 'text/plain'
|
||||
response.contentLength = exportFile.size()
|
||||
response.outputStream << exportFile.bytes
|
||||
|
||||
}
|
||||
} else {
|
||||
response.contentType = 'aplication/octet-stream'
|
||||
response.setHeader('Content-disposition', "attachment; filename=\"${bundle.name}.zip\"")
|
||||
|
||||
ZipOutputStream zipOutputStream = new ZipOutputStream(response.outputStream)
|
||||
bundle.languages.each { lang ->
|
||||
ZipEntry language = new ZipEntry(lang.languageFile.name)
|
||||
zipOutputStream.putNextEntry(language)
|
||||
zipOutputStream.write(lang.languageFile.bytes)
|
||||
}
|
||||
zipOutputStream.close()
|
||||
}
|
||||
} else {
|
||||
redirect action: 'index'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -8,7 +8,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'
|
||||
private static final String STANDARD_LANGUAGE_TAG = 'default'
|
||||
|
||||
HashSet<Bundle> getBundles(boolean noCache = false) {
|
||||
if (!cachedBundles || noCache) {
|
||||
|
||||
@ -3,13 +3,14 @@
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<title><g:layoutTitle default="Translations overview" /></title>
|
||||
<r:require modules="bootstrap"/>
|
||||
<r:layoutResources/>
|
||||
</head>
|
||||
<r:layoutResources/>
|
||||
<link rel="stylesheet" href="${resource(dir: 'css', file: 'translations.css')}" type="text/css">
|
||||
<body>
|
||||
|
||||
<div class="container main-container">
|
||||
<div class="container translations-container">
|
||||
<g:layoutBody />
|
||||
</div>
|
||||
|
||||
|
||||
@ -3,17 +3,11 @@
|
||||
<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>
|
||||
<g:each in="${bundle.languages}" var="language">
|
||||
<g:render template="templates/language" model="${[language: language]}" />
|
||||
</g:each>
|
||||
</body>
|
||||
</html>
|
||||
@ -3,7 +3,6 @@
|
||||
<head>
|
||||
<meta name="layout" content="main"/>
|
||||
<title><g:message code="plugin.translations.overview.index.page.title" /></title>
|
||||
<r:require modules="bootstrap"/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -34,22 +33,20 @@
|
||||
<b>${bundle.name}</b>
|
||||
</td>
|
||||
<td>
|
||||
<div class="action-buttons">
|
||||
<g:link action="edit" params="${[bundleName: bundle.name]}"
|
||||
class="btn btn-default">
|
||||
<g:message code="plugin.translations.action.edit"/>
|
||||
</g:link>
|
||||
<g:link action="export" params="${[bundleName: bundle.name]}"
|
||||
class="btn btn-primary">
|
||||
<g:message code="plugin.translations.action.export"/>
|
||||
</g:link>
|
||||
</div>
|
||||
<g:link action="export" params="${[bundleName: bundle.name]}"
|
||||
class="btn btn-default">
|
||||
<g:message code="plugin.translations.action.export"/>
|
||||
</g:link>
|
||||
<g:link action="edit" params="${[bundleName: bundle.name]}"
|
||||
class="btn btn-primary">
|
||||
<g:message code="plugin.translations.action.edit"/>
|
||||
</g:link>
|
||||
</td>
|
||||
</tr>
|
||||
</g:each>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="total">
|
||||
<div class="translations-total-label">
|
||||
<g:message code="plugin.translations.totalBundles" args="${[bundles.size()]}"/>
|
||||
</div>
|
||||
</g:if>
|
||||
|
||||
@ -1,12 +1,32 @@
|
||||
<g:form action="saveFile" name="${language.languageTag}">
|
||||
<h3>${language.languageTag.toUpperCase()}</h3>
|
||||
<g:textField name="lang" value="${language.languageTag}" hidden="true"/>
|
||||
<g:textField name="bundleName" value="${language.bundle.name}" hidden="true"/>
|
||||
<g:textField name="langFile" value="${language.languageFile.path}" hidden="true"/>
|
||||
<g:each in="${language.translations}" var="translation">
|
||||
<g:set var="key" value="${ts.propertyKey(property: translation)}"/>
|
||||
<label>${key}</label> <g:textField name="translations.${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>
|
||||
<div class="row">
|
||||
<div class="translations-main-block">
|
||||
<g:form action="saveFile" name="${language.languageTag}" class="form-horizontal">
|
||||
<h3>${language.languageTag.toUpperCase()}</h3>
|
||||
<g:textField name="lang" value="${language.languageTag}" hidden="true"/>
|
||||
<g:textField name="bundleName" value="${language.bundle.name}" hidden="true"/>
|
||||
<g:textField name="langFile" value="${language.languageFile.path}" hidden="true"/>
|
||||
<div class="form-group">
|
||||
<g:each in="${language.translations}" var="translation">
|
||||
<g:set var="key" value="${ts.propertyKey(property: translation)}"/>
|
||||
<div class="col-sm-4">
|
||||
<label class="control-label">${key}</label>
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
<g:textField class="form-control" name="translations.${key}"
|
||||
value="${ts.propertyValue(property: translation)}" />
|
||||
</div>
|
||||
<br/>
|
||||
</g:each>
|
||||
</div>
|
||||
|
||||
<div class="pull-right">
|
||||
<g:link class="btn btn-default" action="export" params="[bundleName: language.bundle.name,
|
||||
langTag: language.languageTag]">
|
||||
<g:message code="plugin.translations.action.export"/>
|
||||
</g:link>
|
||||
<g:submitButton name="save" class="btn btn-primary"
|
||||
value="${g.message(code: 'plugin.translations.action.save')}"/>
|
||||
</div>
|
||||
</g:form>
|
||||
</div>
|
||||
</div>
|
||||
@ -12,8 +12,9 @@ table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.main-container {
|
||||
margin-top: 10%;
|
||||
.translations-container {
|
||||
margin-top: 5%;
|
||||
margin-bottom: 5%;
|
||||
border: #000 solid 1px;
|
||||
background-color: #707070;
|
||||
padding: 10px;
|
||||
@ -21,16 +22,20 @@ table {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.total {
|
||||
.translations-total-label {
|
||||
margin: 10px;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
padding-top: 1px;
|
||||
padding-bottom: 1px;
|
||||
}
|
||||
|
||||
.table-hover tbody tr:hover {
|
||||
color: #111;
|
||||
}
|
||||
|
||||
input {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.translations-main-block {
|
||||
margin-left: 25px;
|
||||
margin-right: 25px;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user