FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

briefly consider supporting backslashes to continue properties file l… · dimr/processing@af2d299 · GitHub

Repository navigation

Commit af2d299

Browse files
committed
briefly consider supporting backslashes to continue properties file lines
1 parent dc27365 commit af2d299

1 file changed

Lines changed: 50 additions & 35 deletions

File tree

‎app/src/processing/app/Language.java‎

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@
3333
public class Language {
3434
// static private final String FILE = "processing.app.languages.PDE";
3535
//static private final String LISTING = "processing/app/languages/languages.txt";
36-
36+
3737
// Store the language information in a file separate from the preferences,
3838
// because preferences need the language on load time.
3939
static protected final String PREF_FILE = "language.txt";
4040
static protected final File prefFile = Base.getSettingsFile(PREF_FILE);
41-
41+
4242
/** Single instance of this Language class */
4343
static private volatile Language instance;
44-
44+
4545
/** The system language */
4646
private String language;
47-
47+
4848
/** Available languages */
4949
private HashMap<String, String> languages;
50-
50+
5151
//private ResourceBundle bundle;
5252
//private Settings bundle;
5353
private LanguageBundle bundle;
@@ -57,18 +57,18 @@ private Language() {
5757
String systemLanguage = Locale.getDefault().getLanguage();
5858
language = loadLanguage();
5959
boolean writePrefs = false;
60-
60+
6161
if (language == null) {
6262
language = systemLanguage;
6363
writePrefs = true;
6464
}
65-
65+
6666
// Set available languages
6767
languages = new HashMap<String, String>();
6868
for (String code : listSupported()) {
6969
languages.put(code, Locale.forLanguageTag(code).getDisplayLanguage(Locale.forLanguageTag(code)));
7070
}
71-
71+
7272
// Set default language
7373
if (!languages.containsKey(language)) {
7474
language = "en";
@@ -87,8 +87,8 @@ private Language() {
8787
e.printStackTrace();
8888
}
8989
}
90-
91-
90+
91+
9292
static private String[] listSupported() {
9393
// List of languages in alphabetical order. (Add yours here.)
9494
// Also remember to add it to the corresponding build/build.xml rule.
@@ -99,7 +99,7 @@ static private String[] listSupported() {
9999
"es", // Spanish
100100
"fr", // French, Français
101101
"ja", // Japanese
102-
"ko", // Korean
102+
"ko", // Korean
103103
"nl", // Dutch, Nederlands
104104
"pt", // Portuguese
105105
"tr", // Turkish
@@ -126,7 +126,7 @@ static private String[] listSupported() {
126126

127127

128128
/** Read the saved language */
129-
static private String loadLanguage() {
129+
static private String loadLanguage() {
130130
try {
131131
if (prefFile.exists()) {
132132
String language = PApplet.loadStrings(prefFile)[0];
@@ -140,11 +140,11 @@ static private String loadLanguage() {
140140
}
141141
return null;
142142
}
143-
144-
143+
144+
145145
/**
146-
* Save the language directly to a settings file. This is 'save' and not
147-
* 'set' because a language change requires a restart of Processing.
146+
* Save the language directly to a settings file. This is 'save' and not
147+
* 'set' because a language change requires a restart of Processing.
148148
*/
149149
static public void saveLanguage(String language) {
150150
try {
@@ -154,8 +154,8 @@ static public void saveLanguage(String language) {
154154
}
155155
Base.getPlatform().saveLanguage(language);
156156
}
157-
158-
157+
158+
159159
/** Singleton constructor */
160160
static public Language init() {
161161
if (instance == null) {
@@ -181,13 +181,13 @@ static public String text(String text) {
181181
}
182182
}
183183

184-
184+
185185
static public String interpolate(String text, Object... arguments) {
186186
// return String.format(init().bundle.getString(text), arguments);
187187
return String.format(init().bundle.getString(text), arguments);
188188
}
189189

190-
190+
191191
static public String pluralize(String text, int count) {
192192
// ResourceBundle bundle = init().bundle;
193193
LanguageBundle bundle = init().bundle;
@@ -199,17 +199,17 @@ static public String pluralize(String text, int count) {
199199
}
200200
return interpolate(String.format(fmt, "n"), count);
201201
}
202-
202+
203203

204204
/** Get all available languages */
205205
static public Map<String, String> getLanguages() {
206206
return init().languages;
207207
}
208208

209209

210-
/**
210+
/**
211211
* Get the current language.
212-
* @return two digit ISO code (lowercase)
212+
* @return two digit ISO code (lowercase)
213213
*/
214214
static public String getLanguage() {
215215
return init().language;
@@ -219,7 +219,7 @@ static public String getLanguage() {
219219
// /** Set new language (called by Preferences) */
220220
// static public void setLanguage(String language) {
221221
// this.language = language;
222-
//
222+
//
223223
// try {
224224
// File file = Base.getContentFile("lib/language.txt");
225225
// Base.saveFile(language, file);
@@ -265,14 +265,14 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format, C
265265
}
266266
}
267267
*/
268-
269-
268+
269+
270270
static class LanguageBundle {
271271
Map<String, String> table;
272-
272+
273273
LanguageBundle(String language) throws IOException {
274274
table = new HashMap<String, String>();
275-
275+
276276
String baseFilename = "languages/PDE.properties";
277277
String langFilename = "languages/PDE_" + language + ".properties";
278278

@@ -287,23 +287,38 @@ static class LanguageBundle {
287287
if (userLangFile.exists()) {
288288
langFile = userLangFile;
289289
}
290-
290+
291291
read(baseFile);
292292
read(langFile);
293293
}
294-
294+
295295
void read(File additions) {
296296
String[] lines = PApplet.loadStrings(additions);
297-
for (String line : lines) {
297+
//for (String line : lines) {
298+
for (int i = 0; i < lines.length; i++) {
299+
String line = lines[i];
298300
if ((line.length() == 0) ||
299301
(line.charAt(0) == '#')) continue;
300302

301-
// this won't properly handle = signs being in the text
303+
// this won't properly handle = signs inside in the text
302304
int equals = line.indexOf('=');
303305
if (equals != -1) {
304306
String key = line.substring(0, equals).trim();
305307
String value = line.substring(equals + 1).trim();
306-
308+
309+
/*
310+
// Support for backslashes to continue lines... Nah.
311+
while (line.endsWith("\\")) {
312+
// remove the backslash from the previous
313+
value = value.substring(0, value.length() - 1);
314+
// get the next line
315+
line = lines[++i].trim();
316+
// append the new line to the value (with a space)
317+
// This is imperfect since the prev may end <br>
318+
value += " " + line;
319+
}
320+
*/
321+
307322
// fix \n and \'
308323
value = value.replaceAll("\\\\n", "\n");
309324
value = value.replaceAll("\\\\'", "'");
@@ -312,11 +327,11 @@ void read(File additions) {
312327
}
313328
}
314329
}
315-
330+
316331
String getString(String key) {
317332
return table.get(key);
318333
}
319-
334+
320335
boolean containsKey(String key) {
321336
return table.containsKey(key);
322337
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL