@@ -228,6 +228,11 @@ class Cli {
228228 var fileCount = 0 ;
229229 var fileFailCount = 0 ;
230230
231+ // Test fixtures exercise every supported translation format.
232+ Loreline .translationFormat (" po" , true );
233+ Loreline .translationFormat (" xliff" , true );
234+ Loreline .translationFormat (" csv" , true );
235+
231236 if (FileSystem .exists (path ) && FileSystem .isDirectory (path )) {
232237 var dir = path ;
233238 for (file in FileSystem .readDirectory (dir )) {
@@ -615,6 +620,17 @@ class Cli {
615620 final clearIds = argFlag (args , " clear" );
616621 final lang = argValue (args , " lang" , ! clearIds );
617622 final generateIds = argFlag (args , " auto-ids" );
623+ var format = argValue (args , " format" , false );
624+ if (format == null || format == " " ) format = " lor" ;
625+ if (format != " lor" && format != " po" && format != " xliff" && format != " csv" && format != " tsv" ) {
626+ fail (' Unsupported translation format: $format (expected one of: lor, po, xliff, csv, tsv)' );
627+ }
628+
629+ // Enable alternate translation formats so that an existing file can be
630+ // read back as the merge baseline.
631+ Loreline .translationFormat (" po" , true );
632+ Loreline .translationFormat (" xliff" , true );
633+ Loreline .translationFormat (" csv" , true );
618634
619635 if (! FileSystem .exists (file ) || FileSystem .isDirectory (file ))
620636 fail (' Invalid file: $file ' );
@@ -636,20 +652,25 @@ class Cli {
636652 script = Loreline .parse (content , file , handleFile );
637653 }
638654
639- final basePath = file .substring (0 , file .length - 4 );
640- final translationPath = basePath + " ." + lang + " .lor " ;
655+ final basePath = file .uSubstring (0 , file .uLength () - 4 );
656+ final translationPath = basePath + " ." + lang + " ." + format ;
641657
642658 var existingTranslations : Map <String , Node . NStringLiteral > = null ;
643659 if (FileSystem .exists (translationPath )) {
644660 final transContent = File .getContent (translationPath );
645661 if (transContent .trim ().length > 0 ) {
646- final transScript = Loreline .parse (transContent , translationPath , handleFile );
647- if (transScript != null )
648- existingTranslations = AstUtils .extractTranslations (transScript );
662+ final lorBody = (format == " lor" )
663+ ? transContent
664+ : convertExistingToLor (transContent , format , lang );
665+ if (lorBody != null && lorBody .trim ().length > 0 ) {
666+ final transScript = Loreline .parse (lorBody , translationPath , handleFile );
667+ if (transScript != null )
668+ existingTranslations = AstUtils .extractTranslations (transScript );
669+ }
649670 }
650671 }
651672
652- final output = AstUtils .generateTranslationFile (script , existingTranslations , new Printer () );
673+ final output = Loreline .generateTranslationFile (script , existingTranslations , format , lang );
653674 File .saveContent (translationPath , output );
654675
655676 print (' Translation file ' + (existingTranslations != null ? ' updated' : ' created' ) + ' : ' + translationPath );
@@ -669,6 +690,16 @@ class Cli {
669690
670691 }
671692
693+ function convertExistingToLor (content : String , format : String , locale : String ): String {
694+ return switch (format ) {
695+ case " po" : loreline.translation. PoTranslation .toLoreline (content , locale );
696+ case " xliff" : loreline.translation. XliffTranslation .toLoreline (content , locale );
697+ case " csv" : loreline.translation. CsvTranslation .toLoreline (content , locale );
698+ case " tsv" : loreline.translation. CsvTranslation .tsvToLoreline (content , locale );
699+ case _ : null ;
700+ }
701+ }
702+
672703 function play (file : String ) {
673704
674705 print (" " );
0 commit comments