package com.peterfranza.propertytranslator.translators;

import org.apache.maven.plugin.logging.Log;

import com.peterfranza.propertytranslator.TranslatorConfig;

public class QuestionMarkTranslator implements Translator {

	public String translate(String source) {
		
		if(source == null)
			return null;
		
		source = source.trim();
		
		if(source.length() == 0)
			return "";

		StringBuilder translated=new StringBuilder();
		boolean insideVariable=false;

		// preserves {0} and ${foo} variables

		for (int i=0;i<source.length();i++) {
			char c=source.charAt(i);
			if (insideVariable) {
				translated.append(c);
				continue;
			} if (c=='{') {
				translated.append(c);
				insideVariable=true;
			} else if (c=='}') {
				translated.append(c);
				insideVariable=false;
			} else if (Character.isAlphabetic(c)||Character.isIdeographic(c)) {
				translated.append('?');
			} else {
				translated.append(c);
			}
		}
		return translated.toString();
	}
	
	public void reconfigure(TranslatorConfig config, String sourceLanguage) {
		//NO-OP
	}

	public void open() {
		//NO-OP
	}

	public void close() {
		//NO-OP
	}

	@Override
	public void printStats(Log log) {
		//NO-OP
	}
	
}

@@ -570,30 +570,24 @@
 %0A%09%09%09if (
-insideVariable
+c == '%7D'
 ) %7B%0A%09%09%09%09
@@ -616,30 +616,51 @@
 %09%09%09%09
-continu
+insideVariable = fals
 e;%0A%09%09%09%7D
+ else
  if (c
+ 
 ==
+ 
 '%7B')
@@ -706,17 +706,19 @@
 Variable
-=
+ = 
 true;%0A%09%09
@@ -733,14 +733,22 @@
 if (
-c=='%7D'
+insideVariable
 ) %7B%0A
@@ -777,34 +777,8 @@
 c);%0A
-%09%09%09%09insideVariable=false;%0A
 %09%09%09%7D
@@ -816,10 +816,12 @@
 c(c)
+ 
 %7C%7C
+ 
 Char

fix a bug where text would not be replaced with question marks after the first variable was encountered.