Skip to content

Commit

Permalink
accept english and local translation
Browse files Browse the repository at this point in the history
  • Loading branch information
jflamy committed Feb 18, 2025
1 parent 1736082 commit 8507047
Showing 1 changed file with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
Expand All @@ -14,6 +17,7 @@
import org.slf4j.LoggerFactory;

import app.owlcms.data.jpa.JPAService;
import app.owlcms.i18n.Translator;
import ch.qos.logback.classic.Logger;

public class TechnicalOfficialReader {
Expand Down Expand Up @@ -73,19 +77,28 @@ public List<TechnicalOfficial> importFromXLS(InputStream is, StringBuilder error

private int[] findColumnIndices(Row headerRow) {
int[] indices = new int[6]; // One for each field
Map<String, Integer> headerMap = new HashMap<>();

for (Cell cell : headerRow) {
String header = cell.getStringCellValue().trim();
int colIndex = cell.getColumnIndex();

headerMap.put(header, colIndex);

String englishHeader = Translator.translate("TechnicalOfficial."+header, Locale.ENGLISH);
headerMap.put(englishHeader, colIndex);

switch (header) {
case LAST_NAME: indices[0] = colIndex; break;
case FIRST_NAME: indices[1] = colIndex; break;
case LEVEL: indices[2] = colIndex; break;
case IWF_ID: indices[3] = colIndex; break;
case FEDERATION: indices[4] = colIndex; break;
case FEDERATION_ID: indices[5] = colIndex; break;
}
String translatedHeader = Translator.translate("TechnicalOfficial."+header);
headerMap.put(translatedHeader, colIndex);
}

indices[0] = headerMap.getOrDefault(LAST_NAME, -1);
indices[1] = headerMap.getOrDefault(FIRST_NAME, -1);
indices[2] = headerMap.getOrDefault(LEVEL, -1);
indices[3] = headerMap.getOrDefault(IWF_ID, -1);
indices[4] = headerMap.getOrDefault(FEDERATION, -1);
indices[5] = headerMap.getOrDefault(FEDERATION_ID, -1);

return indices;
}

Expand Down

0 comments on commit 8507047

Please sign in to comment.