mirror of
https://github.com/Prominence/grails-translations-plugin.git
synced 2026-01-09 19:06:41 +03:00
Added test functionality (getting list of bundles with translations).
This commit is contained in:
parent
9d7c146f99
commit
fe06a6d5d3
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,4 +2,5 @@
|
|||||||
.project
|
.project
|
||||||
target
|
target
|
||||||
.idea
|
.idea
|
||||||
*.zip
|
*.zip
|
||||||
|
.slcache
|
||||||
@ -16,6 +16,8 @@ grails.project.fork = [
|
|||||||
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
|
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
grails.server.port.http = 8082
|
||||||
|
|
||||||
grails.project.dependency.resolver = "maven" // or ivy
|
grails.project.dependency.resolver = "maven" // or ivy
|
||||||
grails.project.dependency.resolution = {
|
grails.project.dependency.resolution = {
|
||||||
// inherit Grails' default dependencies
|
// inherit Grails' default dependencies
|
||||||
@ -40,9 +42,11 @@ grails.project.dependency.resolution = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
build(":release:3.0.1",
|
build(':release:3.0.1',
|
||||||
":rest-client-builder:1.0.3") {
|
':rest-client-builder:1.0.3') {
|
||||||
export = false
|
export = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
build(':tomcat:7.0.55')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,3 +20,6 @@ log4j = {
|
|||||||
'org.hibernate',
|
'org.hibernate',
|
||||||
'net.sf.ehcache.hibernate'
|
'net.sf.ehcache.hibernate'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grails.views.gsp.encoding = "UTF-8"
|
||||||
|
grails.converters.encoding = "UTF-8"
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package by.prominence.translations
|
||||||
|
|
||||||
|
class TranslationsOverviewController {
|
||||||
|
|
||||||
|
def bundleService
|
||||||
|
|
||||||
|
def index() { }
|
||||||
|
|
||||||
|
def showBundles() {
|
||||||
|
|
||||||
|
render view: 'showBundles', model: [bundles: bundleService.getBundles()]
|
||||||
|
}
|
||||||
|
}
|
||||||
11
grails-app/domain/by/prominence/translations/Bundle.groovy
Normal file
11
grails-app/domain/by/prominence/translations/Bundle.groovy
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package by.prominence.translations
|
||||||
|
|
||||||
|
class Bundle {
|
||||||
|
|
||||||
|
String name
|
||||||
|
List<File> propertiesList = new ArrayList<>()
|
||||||
|
|
||||||
|
public void addPropertyFile(File file) {
|
||||||
|
propertiesList.add(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package by.prominence.translations
|
||||||
|
|
||||||
|
class BundleProperties {
|
||||||
|
|
||||||
|
Bundle bundle
|
||||||
|
Properties properties
|
||||||
|
|
||||||
|
}
|
||||||
0
grails-app/i18n/anotherBundle.properties
Normal file
0
grails-app/i18n/anotherBundle.properties
Normal file
0
grails-app/i18n/anotherBundle_af.properties
Normal file
0
grails-app/i18n/anotherBundle_af.properties
Normal file
0
grails-app/i18n/anotherBundle_as.properties
Normal file
0
grails-app/i18n/anotherBundle_as.properties
Normal file
0
grails-app/i18n/anotherBundle_br.properties
Normal file
0
grails-app/i18n/anotherBundle_br.properties
Normal file
0
grails-app/i18n/anotherBundle_de.properties
Normal file
0
grails-app/i18n/anotherBundle_de.properties
Normal file
0
grails-app/i18n/anotherBundle_en.properties
Normal file
0
grails-app/i18n/anotherBundle_en.properties
Normal file
0
grails-app/i18n/anotherBundle_ru.properties
Normal file
0
grails-app/i18n/anotherBundle_ru.properties
Normal file
0
grails-app/i18n/anotherBundle_uk.properties
Normal file
0
grails-app/i18n/anotherBundle_uk.properties
Normal file
1
grails-app/i18n/messages.properties
Normal file
1
grails-app/i18n/messages.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
test.message = Test message here
|
||||||
1
grails-app/i18n/messages_de.properties
Normal file
1
grails-app/i18n/messages_de.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
test.message = Test message here
|
||||||
1
grails-app/i18n/messages_en.properties
Normal file
1
grails-app/i18n/messages_en.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
test.message = Test message here
|
||||||
1
grails-app/i18n/messages_ru.properties
Normal file
1
grails-app/i18n/messages_ru.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
test.message = Тестовое сообщение
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
package by.prominence.translations
|
||||||
|
|
||||||
|
class BundleService {
|
||||||
|
|
||||||
|
private HashSet<Bundle> cachedBundles
|
||||||
|
|
||||||
|
private static final defaultFolder = "i18n"
|
||||||
|
|
||||||
|
HashSet<Bundle> getBundles(boolean noCache = false) {
|
||||||
|
if (!cachedBundles || noCache) {
|
||||||
|
cachedBundles = searchForBundles().values()
|
||||||
|
}
|
||||||
|
return cachedBundles
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Bundle> searchForBundles() {
|
||||||
|
Map<String, Bundle> result = new HashMap<>()
|
||||||
|
|
||||||
|
new File('.').eachFileRecurse() { File file ->
|
||||||
|
if(file.name.endsWith('.properties')) {
|
||||||
|
if (isTranslationProperty(file)) {
|
||||||
|
|
||||||
|
String bundleName = getBundleName(file.name)
|
||||||
|
if (!result.get(bundleName)) {
|
||||||
|
Bundle bundle = new Bundle(name: bundleName)
|
||||||
|
result.put(bundleName, bundle)
|
||||||
|
}
|
||||||
|
result.get(bundleName).addPropertyFile(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTranslationProperty(File file) {
|
||||||
|
return file.parent.contains(defaultFolder)
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFileNameWithoutExtension(String filename) {
|
||||||
|
return filename.substring(0, filename.lastIndexOf('.'))
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getBundleName(String filename) {
|
||||||
|
return filename.indexOf('_') < 0 ?
|
||||||
|
getFileNameWithoutExtension(filename) :
|
||||||
|
filename.substring(0, filename.indexOf('_'))
|
||||||
|
}
|
||||||
|
}
|
||||||
11
grails-app/views/translationsOverview/index.gsp
Normal file
11
grails-app/views/translationsOverview/index.gsp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<%@ page contentType="text/html;charset=UTF-8" %>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<title>Test</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<g:message code="test.message" />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
24
grails-app/views/translationsOverview/showBundles.gsp
Normal file
24
grails-app/views/translationsOverview/showBundles.gsp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<%@ page contentType="text/html;charset=UTF-8" %>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<title>bundles</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<g:if test="${bundles}">
|
||||||
|
<g:each in="${bundles}" var="bundle">
|
||||||
|
${bundle.name} <br />
|
||||||
|
<g:each in="${bundle.propertiesList}" var="properties">
|
||||||
|
-> ${properties.name} <br />
|
||||||
|
${properties.text.eachLine { line ->
|
||||||
|
print('----------> ' + line + '<br/>')
|
||||||
|
}}
|
||||||
|
</g:each>
|
||||||
|
</g:each>
|
||||||
|
</g:if>
|
||||||
|
<g:else>
|
||||||
|
There is no bundles!
|
||||||
|
</g:else>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user