@@ -145,7 +145,7 @@ public void execute() throws BuildException {
145145 if (outputSrcLang ) {
146146 if (bdlLangs .contains (srcLang )) {
147147 exportLanguageResource (client , bf , srcLang , outDir ,
148- outContentOpt , bundleLayout , langIdStyle , langMap );
148+ outContentOpt , bundleLayout , langIdStyle , langMap , srcLang );
149149 } else {
150150 getProject ().log ("The specified source language (" + srcLang
151151 + ") does not exist in the bundle:" + bundleId , Project .MSG_WARN );
@@ -155,7 +155,7 @@ public void execute() throws BuildException {
155155 for (String tgtLang : tgtLangs ) {
156156 if (bdlLangs .contains (tgtLang )) {
157157 exportLanguageResource (client , bf , tgtLang , outDir ,
158- outContentOpt , bundleLayout , langIdStyle , langMap );
158+ outContentOpt , bundleLayout , langIdStyle , langMap , srcLang );
159159 } else {
160160 getProject ().log ("The specified target language (" + tgtLang
161161 + ") does not exist in the bundle:" + bundleId , Project .MSG_WARN );
@@ -175,11 +175,12 @@ public void execute() throws BuildException {
175175 * @param bundleLayout
176176 * @param langIdStyle
177177 * @param langMap
178+ * @param srcLang
178179 * @throws BuildException
179180 */
180181 private void exportLanguageResource (ServiceClient client , SourceBundleFile bf , String language ,
181182 File outBaseDir , OutputContentOption outContntOpt , BundleLayout bundleLayout ,
182- LanguageIdStyle langIdStyle , Map <String , String > langMap )
183+ LanguageIdStyle langIdStyle , Map <String , String > langMap , String srcLang )
183184 throws BuildException {
184185 String srcFileName = bf .getFile ().getName ();
185186 String relPath = bf .getRelativePath ();
@@ -189,14 +190,30 @@ private void exportLanguageResource(ServiceClient client, SourceBundleFile bf, S
189190 switch (bundleLayout ) {
190191 case LANGUAGE_SUFFIX : {
191192 File dir = (new File (outBaseDir , relPath )).getParentFile ();
192- int idx = srcFileName .lastIndexOf ('.' );
193- String tgtName = null ;
194- if (idx < 0 ) {
195- tgtName = srcFileName + "_" + getLanguageId (language , langIdStyle , langMap );
196- } else {
197- tgtName = srcFileName .substring (0 , idx ) + "_" + getLanguageId (language , langIdStyle , langMap )
198- + srcFileName .substring (idx );
193+
194+ String tgtName = srcFileName ;
195+ // Compose file name if the output language is not the source language
196+ if (!language .equals (srcLang )) {
197+ String baseName = srcFileName ;
198+ String extension = "" ;
199+ int extensionIndex = srcFileName .lastIndexOf ('.' );
200+ if (extensionIndex > 0 ) {
201+ baseName = srcFileName .substring (0 , extensionIndex );
202+ extension = srcFileName .substring (extensionIndex );
203+ }
204+
205+ // checks if the source file's base name (without extension) ends with
206+ // source language code suffix, e.g. foo_en => foo
207+ String srcLangSuffix = "_" + getLanguageId (srcLang , langIdStyle , langMap );
208+ if (baseName .endsWith (srcLangSuffix )) {
209+ // truncates source the source language suffix from base name
210+ baseName = baseName .substring (0 , baseName .length () - srcLangSuffix .length ());
211+ }
212+
213+ // append target language suffix to the base name, e.g. foo => foo_de
214+ tgtName = baseName + "_" + getLanguageId (language , langIdStyle , langMap ) + extension ;
199215 }
216+
200217 outputFile = new File (dir , tgtName );
201218 break ;
202219 }
0 commit comments