return GitBlitWebSession.get().getLocale().getLanguage();\r
}\r
\r
+ protected String getCountryCode() {\r
+ return GitBlitWebSession.get().getLocale().getCountry().toLowerCase();\r
+ }\r
+ \r
protected TimeUtils getTimeUtils() {\r
if (timeUtils == null) {\r
ResourceBundle bundle; \r
}\r
\r
private String readDefaultMarkdown(String file) {\r
- String content = readDefaultMarkdown(file, getLanguageCode());\r
- if (StringUtils.isEmpty(content)) {\r
- content = readDefaultMarkdown(file, null);\r
- }\r
- return content;\r
- }\r
+ String base = file.substring(0, file.lastIndexOf('.'));\r
+ String ext = file.substring(file.lastIndexOf('.'));\r
+ String lc = getLanguageCode();\r
+ String cc = getCountryCode();\r
\r
- private String readDefaultMarkdown(String file, String lc) {\r
+ // try to read file_en-us.ext, file_en.ext, file.ext\r
+ List<String> files = new ArrayList<String>();\r
if (!StringUtils.isEmpty(lc)) {\r
- // convert to file_lc.mkd\r
- file = file.substring(0, file.lastIndexOf('.')) + "_" + lc\r
- + file.substring(file.lastIndexOf('.'));\r
+ if (!StringUtils.isEmpty(cc)) {\r
+ files.add(base + "_" + lc + "-" + cc + ext);\r
+ files.add(base + "_" + lc + "_" + cc + ext);\r
+ }\r
+ files.add(base + "_" + lc + ext);\r
}\r
- String message;\r
- try {\r
- ContextRelativeResource res = WicketUtils.getResource(file);\r
- InputStream is = res.getResourceStream().getInputStream();\r
- InputStreamReader reader = new InputStreamReader(is, Constants.CHARACTER_ENCODING);\r
- message = MarkdownUtils.transformMarkdown(reader);\r
- reader.close();\r
- } catch (ResourceStreamNotFoundException t) {\r
- if (lc == null) {\r
- // could not find default language resource\r
+ files.add(file);\r
+ \r
+ for (String name : files) {\r
+ String message;\r
+ InputStreamReader reader = null;\r
+ try {\r
+ ContextRelativeResource res = WicketUtils.getResource(name);\r
+ InputStream is = res.getResourceStream().getInputStream();\r
+ reader = new InputStreamReader(is, Constants.CHARACTER_ENCODING);\r
+ message = MarkdownUtils.transformMarkdown(reader);\r
+ reader.close();\r
+ return message;\r
+ } catch (ResourceStreamNotFoundException t) {\r
+ continue;\r
+ } catch (Throwable t) {\r
message = MessageFormat.format(getString("gb.failedToReadMessage"), file);\r
error(message, t, false);\r
- } else {\r
- // ignore so we can try default language resource\r
- message = null;\r
- }\r
- } catch (Throwable t) {\r
- message = MessageFormat.format(getString("gb.failedToReadMessage"), file);\r
- error(message, t, false);\r
+ return message;\r
+ } finally {\r
+ if (reader != null) {\r
+ try {\r
+ reader.close();\r
+ } catch (Exception e) {\r
+ }\r
+ }\r
+ } \r
}\r
- return message;\r
+ return MessageFormat.format(getString("gb.failedToReadMessage"), file);\r
}\r
}\r
import java.io.InputStream;\r
import java.io.InputStreamReader;\r
import java.text.MessageFormat;\r
+import java.util.ArrayList;\r
import java.util.List;\r
\r
import org.apache.wicket.Component;\r
}\r
\r
private String readDefaultMarkdown(String file) {\r
- String content = readDefaultMarkdown(file, getLanguageCode());\r
- if (StringUtils.isEmpty(content)) {\r
- content = readDefaultMarkdown(file, null);\r
- }\r
- return content;\r
- }\r
- \r
- private String readDefaultMarkdown(String file, String lc) {\r
+ String base = file.substring(0, file.lastIndexOf('.'));\r
+ String ext = file.substring(file.lastIndexOf('.'));\r
+ String lc = getLanguageCode();\r
+ String cc = getCountryCode();\r
+\r
+ // try to read file_en-us.ext, file_en.ext, file.ext\r
+ List<String> files = new ArrayList<String>();\r
if (!StringUtils.isEmpty(lc)) {\r
- // convert to file_lc.mkd\r
- file = file.substring(0, file.lastIndexOf('.')) + "_" + lc + file.substring(file.lastIndexOf('.'));\r
+ if (!StringUtils.isEmpty(cc)) {\r
+ files.add(base + "_" + lc + "-" + cc + ext);\r
+ files.add(base + "_" + lc + "_" + cc + ext);\r
+ }\r
+ files.add(base + "_" + lc + ext);\r
}\r
- String message;\r
- try { \r
- InputStream is = GitBlit.self().getResourceAsStream(file);\r
- InputStreamReader reader = new InputStreamReader(is, Constants.CHARACTER_ENCODING);\r
- message = MarkdownUtils.transformMarkdown(reader);\r
- reader.close();\r
- } catch (ResourceStreamNotFoundException t) {\r
- if (lc == null) {\r
- // could not find default language resource\r
+ files.add(file);\r
+\r
+ for (String name : files) {\r
+ String message;\r
+ InputStreamReader reader = null;\r
+ try {\r
+ ContextRelativeResource res = WicketUtils.getResource(name);\r
+ InputStream is = res.getResourceStream().getInputStream();\r
+ reader = new InputStreamReader(is, Constants.CHARACTER_ENCODING);\r
+ message = MarkdownUtils.transformMarkdown(reader);\r
+ reader.close();\r
+ return message;\r
+ } catch (ResourceStreamNotFoundException t) {\r
+ continue;\r
+ } catch (Throwable t) {\r
message = MessageFormat.format(getString("gb.failedToReadMessage"), file);\r
error(message, t, false);\r
- } else {\r
- // ignore so we can try default language resource\r
- message = null;\r
- }\r
- } catch (Throwable t) {\r
- message = MessageFormat.format(getString("gb.failedToReadMessage"), file);\r
- error(message, t, false);\r
+ return message;\r
+ } finally {\r
+ if (reader != null) {\r
+ try {\r
+ reader.close();\r
+ } catch (Exception e) {\r
+ }\r
+ }\r
+ } \r
}\r
- return message;\r
+ return MessageFormat.format(getString("gb.failedToReadMessage"), file);\r
}\r
}\r