mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
translation generator
This commit is contained in:
@@ -88,6 +88,8 @@ To add a new language, create a new file in that directory.
|
|||||||
The name of the file should be the two-letters [ISO-639-1 language code](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
|
The name of the file should be the two-letters [ISO-639-1 language code](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
|
||||||
The language has to be referenced in the `languages.properties` file to be picked up.
|
The language has to be referenced in the `languages.properties` file to be picked up.
|
||||||
|
|
||||||
|
When adding new terms translations, add them in en.properties then run `mvn -e groovy:execute -Pi18n``. It will parse the english file and add new entries in the other translation files.
|
||||||
|
|
||||||
Copyright and license
|
Copyright and license
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|||||||
52
pom.xml
52
pom.xml
@@ -515,5 +515,57 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>i18n</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.gmaven</groupId>
|
||||||
|
<artifactId>gmaven-plugin</artifactId>
|
||||||
|
<version>1.4</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<configuration>
|
||||||
|
<properties>
|
||||||
|
<dir>${basedir}/src/main/resources/i18n/</dir>
|
||||||
|
</properties>
|
||||||
|
<scriptpath>
|
||||||
|
<element>${basedir}/src/main/script</element>
|
||||||
|
</scriptpath>
|
||||||
|
<source>
|
||||||
|
def dir = project.properties['dir'];
|
||||||
|
new
|
||||||
|
I18nGenerator().generate(dir);
|
||||||
|
</source>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>2.3</version>
|
||||||
|
<configuration>
|
||||||
|
<webResources>
|
||||||
|
<resource>
|
||||||
|
<directory>target/generated-sources/angularjs/</directory>
|
||||||
|
<targetPath>templates</targetPath>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/script/</directory>
|
||||||
|
<includes>
|
||||||
|
<include>*.js</include>
|
||||||
|
</includes>
|
||||||
|
<targetPath>js</targetPath>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</webResources>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public class InternationalizationDevelopmentFilter implements Filter {
|
|||||||
String var = m.group(1);
|
String var = m.group(1);
|
||||||
Object replacement = props.get(var);
|
Object replacement = props.get(var);
|
||||||
String replacementValue = replacement == null ? var : replacement
|
String replacementValue = replacement == null ? var : replacement
|
||||||
.toString();
|
.toString().split("#")[0].trim();
|
||||||
m.appendReplacement(sb, replacementValue);
|
m.appendReplacement(sb, replacementValue);
|
||||||
}
|
}
|
||||||
m.appendTail(sb);
|
m.appendTail(sb);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class HTMLConcat {
|
|||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
String var = m.group(1);
|
String var = m.group(1);
|
||||||
Object replacement = props.get(var);
|
Object replacement = props.get(var);
|
||||||
m.appendReplacement(sb, replacement.toString());
|
m.appendReplacement(sb, replacement == null ? var : replacement.toString().split("#")[0].trim());
|
||||||
}
|
}
|
||||||
m.appendTail(sb);
|
m.appendTail(sb);
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
|||||||
49
src/main/script/I18nGenerator.groovy
Normal file
49
src/main/script/I18nGenerator.groovy
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class I18nGenerator {
|
||||||
|
|
||||||
|
public void generate(String directory) throws Exception {
|
||||||
|
|
||||||
|
File dir = new File(directory);
|
||||||
|
List<String> enLines = FileUtils.readLines(new File(dir,
|
||||||
|
"en.properties"), "UTF-8");
|
||||||
|
|
||||||
|
for (File file : dir.listFiles()) {
|
||||||
|
if ("languages.properties".equals(file.getName())
|
||||||
|
|| "en.properties".equals(file.getName()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
List<String> newLines = new ArrayList<String>();
|
||||||
|
List<String> langLines = FileUtils.readLines(file, "UTF-8");
|
||||||
|
|
||||||
|
int j = 0;
|
||||||
|
for (int i = 0; i < enLines.size(); i++) {
|
||||||
|
|
||||||
|
String enLine = enLines.get(i);
|
||||||
|
String langLine = langLines.get(j);
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(enLine)) {
|
||||||
|
|
||||||
|
String key = enLine.split("=")[0];
|
||||||
|
if (langLine.startsWith(key)) {
|
||||||
|
newLines.add(langLine);
|
||||||
|
} else {
|
||||||
|
newLines.add(enLine + " ####### Needs translation");
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newLines.add(null);
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
newLines.add(null);
|
||||||
|
FileUtils.writeLines(file, "UTF-8", newLines);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user