MNG-560: Added initLocalesList() and codeToLocale() methods to honnor correctly locales parameter; Added how to documentation to contribute a new translation; Added a test project

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@280130 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Vincent Siveton 2005-09-11 13:24:56 +00:00
parent 42718256a5
commit f6cc2c6b9b
14 changed files with 600 additions and 16 deletions

View File

@ -144,6 +144,9 @@ public class DoxiaMojo
private Map attributes; private Map attributes;
/** /**
* A comma separated list of locales supported by Maven. The first valid token will be the default Locale
* for this instance of the Java Virtual Machine.
*
* @parameter expression="${locales} * @parameter expression="${locales}
*/ */
private String locales; private String locales;
@ -252,22 +255,7 @@ public class DoxiaMojo
{ {
categorizeReports( reports ); categorizeReports( reports );
if ( locales == null ) initLocalesList();
{
localesList.add( defaultLocale );
}
else
{
// The first token is the default locale
StringTokenizer st = new StringTokenizer( locales, "," );
while ( st.hasMoreTokens() )
{
localesList.add( new Locale( st.nextToken().trim() ) );
}
defaultLocale = (Locale) localesList.get( 0 );
}
Locale.setDefault( defaultLocale ); Locale.setDefault( defaultLocale );
@ -465,6 +453,68 @@ subprojects...
} }
} }
/**
* Init the <code>localesList</code> variable.
* <p>If <code>locales</code> variable is available, the first valid token will be the <code>defaultLocale</code>
* for this instance of the Java Virtual Machine.</p>
*/
private void initLocalesList()
{
if ( locales == null )
{
localesList.add( defaultLocale );
return;
}
String[] localesArray = StringUtils.split( locales, "," );
boolean defaultLocaleWasSet = false;
for ( int i = 0; i < localesArray.length; i++ )
{
Locale locale = codeToLocale( localesArray[i] );
if ( locale != null )
{
if ( !Arrays.asList( Locale.getAvailableLocales() ).contains( locale ) )
{
getLog().warn( "The locale parsed defined by '" + locale
+ "' is not available in this Java Virtual Machine ("
+ System.getProperty( "java.version" ) + " from "
+ System.getProperty( "java.vendor" ) + ") - IGNORING" );
continue;
}
if ( !i18n.getBundle( "site-plugin", locale ).getLocale().getLanguage().equals( locale.getLanguage() ) )
{
StringBuffer sb = new StringBuffer();
sb.append( "The locale '" ).append( locale ).append( "' (" );
sb.append( locale.getDisplayName( Locale.ENGLISH ) );
sb.append( ") is not currently support by Maven - IGNORING. " );
sb.append( "\n" );
sb.append( "Contribution are welcome and greatly appreciated! " );
sb.append( "\n" );
sb.append( "If you want to contribute a new translation, please visit " );
sb.append( "http://maven.apache.org/maven2/plugins/maven-site-plugin/i18n.html " );
sb.append( "for detailed instructions." );
getLog().warn( sb.toString() );
continue;
}
localesList.add( locale );
if ( !defaultLocaleWasSet )
{
defaultLocale = locale;
defaultLocaleWasSet = true;
}
}
}
}
private String getReportsMenu( Locale locale ) private String getReportsMenu( Locale locale )
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
@ -1183,4 +1233,53 @@ subprojects...
return "Default"; return "Default";
} }
/**
* Converts a locale code like "en", "en_US" or "en_US_win" to a <code>java.util.Locale</code>
* object.
* <p>If localeCode = <code>default</code>, return the current value of the default locale for this instance
* of the Java Virtual Machine.</p>
*
* @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html">java.util.Locale#getDefault()</a>
* @param localeCode the locale code string.
* @return a java.util.Locale object instancied or null if errors occurred
*/
private Locale codeToLocale( final String localeCode )
{
if ( localeCode == null )
{
return null;
}
if ( localeCode.equalsIgnoreCase( "default" ) )
{
return Locale.getDefault();
}
String language = "";
String country = "";
String variant = "";
StringTokenizer tokenizer = new StringTokenizer( localeCode, "_" );
if ( tokenizer.countTokens() > 3 )
{
getLog().warn( "Invalid java.util.Locale format for '" + localeCode + "' entry - IGNORING" );
return null;
}
if ( tokenizer.hasMoreTokens() )
{
language = tokenizer.nextToken();
if ( tokenizer.hasMoreTokens() )
{
country = tokenizer.nextToken();
if ( tokenizer.hasMoreTokens() )
{
variant = tokenizer.nextToken();
}
}
}
return new Locale( language, country, variant );
}
} }

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<project name="Maven Site plugin">
<bannerLeft>
<name>Maven Site plugin</name>
<src>http://maven.apache.org/images/apache-maven-project.png</src>
<href>http://maven.apache.org/</href>
</bannerLeft>
<bannerRight>
<src>http://maven.apache.org/images/maven-small.gif</src>
</bannerRight>
<body>
<links>
<item name="Maven 2" href="http://maven.apache.org/maven2/"/>
</links>
<menu name="Overview">
<item name="i18n" href="/i18n.html"/>
</menu>
${reports}
</body>
</project>

View File

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<document>
<properties>
<title>Internationalization</title>
<author email="vincent.siveton@gmail.com">Vincent Siveton</author>
</properties>
<body>
<section name="Supported languages">
<p>
<ul>
<li>
Maven-site-plugin
<br />
<table>
<tr>
<th>Languages available</th>
<th>
Files
<a href="#note">*</a>
</th>
</tr>
<tr>
<td>English</td>
<td>
<a href="http://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins/maven-site-plugin/src/main/resources/site-plugin_en.properties">
See
</a>
</td>
</tr>
<tr>
<td>French</td>
<td>
<a href="http://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins/maven-site-plugin/src/main/resources/site-plugin_fr.properties">
See
</a>
</td>
</tr>
</table>
<br />
</li>
<li>
Maven-project-info-reports-plugin
<br />
<table>
<tr>
<th>Languages available</th>
<th>
Files
<a href="#note">*</a>
</th>
</tr>
<tr>
<td>English</td>
<td>
<a href="http://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins/maven-project-info-reports-plugin/src/main/resources/project-info-report_en.properties">
See
</a>
</td>
</tr>
<tr>
<td>French</td>
<td>
<a href="http://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties">
See
</a>
</td>
</tr>
</table>
<br />
</li>
</ul>
<a name="note">
* The files linked above are the files used in the
latest development code. So the file may be newer
than the one included in the latest release.
</a>
</p>
</section>
<section name="Instructions for translators">
<p>
If your language is not currently supported and you want
to contribute a translation, follow these steps:
<ol>
<li>
Download one of the text files linked above as
the base for your translation. For instance, the
English file.
</li>
<li>
Rename the file with the wanted locale. For
example, site-plugin_de.properties for a new
German translation for the Maven-site-plugin.
</li>
<li>
Translate the file contents using your preferred
text editor. Make sure you save the file with
UTF-8 encoding.
</li>
<li>
Send the file to
<a href="mailto:dev@maven.apache.org?subject=[M2] Translation proposal">
dev@maven.apache.org
</a>
or post it in the tracker at
<a href="http://jira.codehaus.org/browse/MNG">
http://jira.codehaus.org/browse/MNG
</a>.
</li>
</ol>
</p>
</section>
</body>
</document>

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugin.site.test9</groupId>
<artifactId>site-plugin-test9</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<inceptionYear>2005</inceptionYear>
<name>Maven Site Plugin Test9</name>
<description>MNG-560 honnor locales.</description> -->
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<developers>
<developer>
<id>vsiveton</id>
<name>Vincent Siveton</name>
<email>vsiveton@apache.org</email>
<organization>Apache Software Foundation</organization>
<roles>
<role>Java Developer</role>
</roles>
<timezone>-5</timezone>
</developer>
</developers>
<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
</plugins>
</reporting>
<build>
<plugins>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<outputEncoding>utf-8</outputEncoding>
<locales>en,FR_CA,DE_qq_qq_qq,de</locales>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,12 @@
------
Configuring Site Plugin
------
Vincent Siveton
------
18 August 2005
------
Override
Todo

View File

@ -0,0 +1,12 @@
------
Configuring Site Plugin
------
Vincent Siveton
------
18 August 2005
------
Site Plugin Test
Todo

View File

@ -0,0 +1,12 @@
------
Configuring Site Plugin
------
Vincent Siveton
------
18 August 2005
------
Test pour Site Plugin
Todo

View File

@ -0,0 +1,12 @@
------
Configuring Site Plugin
------
Vincent Siveton
------
18 August 2005
------
Override
Todo

View File

@ -0,0 +1,12 @@
------
Configuring Site Plugin
------
Vincent Siveton
------
18 August 2005
------
Test pour Site Plugin
Todo

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<document>
<properties>
<title>Bienvenue</title>
<author email="vincent.siveton">Vincent Siveton</author>
</properties>
<body>
<section name="Bienvenue">
<p>
Override
</p>
</section>
</body>
</document>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<document>
<properties>
<title>Bienvenue</title>
<author email="vincent.siveton">Vincent Siveton</author>
</properties>
<body>
<section name="Bienvenue">
<p>
Test pour Maven Site Plugin.
</p>
</section>
</body>
</document>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<project name="Maven Site">
<bannerLeft>
<name>Maven Site</name>
<src>http://maven.apache.org/images/apache-maven-project.png</src>
<href>http://maven.apache.org/</href>
</bannerLeft>
<bannerRight>
<src>http://maven.apache.org/images/maven-small.gif</src>
</bannerRight>
<body>
<links>
<item name="Maven 2" href="http://maven.apache.org/maven2/"/>
</links>
<menu name="Overview">
<item name="Test page" href="/test.html"/>
</menu>
${reports}
</body>
</project>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<project name="Maven Site">
<bannerLeft>
<name>Maven Site</name>
<src>http://maven.apache.org/images/apache-maven-project.png</src>
<href>http://maven.apache.org/</href>
</bannerLeft>
<bannerRight>
<src>http://maven.apache.org/images/maven-small.gif</src>
</bannerRight>
<body>
<links>
<item name="Maven 2" href="http://maven.apache.org/maven2/"/>
</links>
<menu name="Resume">
<item name="Page de test" href="/test.html"/>
</menu>
${reports}
</body>
</project>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<document>
<properties>
<title>Welcome</title>
<author email="vincent.siveton">Vincent Siveton</author>
</properties>
<body>
<section name="Welcome to Maven">
<p>
Test the Maven Site Plugin.
</p>
</section>
</body>
</document>