Created
December 6, 2012 15:31
-
-
Save sheenobu/4225353 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface GenderModifier { | |
| public void visit(GenderWords words); | |
| } | |
| class PropertiesTranslationGenderModifier implements GenderModifier { | |
| final String prefix; | |
| final Properties properties; | |
| final Locale locale; | |
| public void visit(GenderWords words) { | |
| words.setPossessive(properties.get("genderTranslator." + locale.toString() + "." + prefix + ".possessive")); | |
| words.setReflexivePronoun(properties.get("genderTranslator." + locale.toString() + "." + prefix + ".reflexivePronoun")); | |
| words.setPronoun(properties.get("genderTranslator." + locale.toString() + "." + prefix + ".pronoun")); | |
| } | |
| public PropertiesTranslationGenderModifier(String prefix, Properties properties,Locale locale) { | |
| this.prefix = prefix; | |
| this.properties = properties; | |
| this.locale = locale; | |
| } | |
| } | |
| class DynamicGenderModifierFactory { | |
| Properties properties; | |
| Locale locale; | |
| public DynamicGenderModifierFactory(Locale locale) { | |
| this.locale = locale; | |
| properties = new Properties(); | |
| properties.load(new FileReader(new File("translations.properties"))); | |
| } | |
| public GenderModifier build(String gender) { | |
| //YAY WE SUPPORT UNICODE | |
| return new PropertiesTranslationGenderModifier(gender.toLowerCase.substring(0,1),properties,locale); | |
| } | |
| } | |
| class GenderWords { | |
| ..getters/setters.. | |
| public void genderModifier() { | |
| new DynamicGenderModifierFactory(Locale.getCurrentLocale()).build(gender).visit(this); | |
| } | |
| } | |
| translations.properties | |
| genderTranslator.en.f.possessive = ... | |
| genderTranslator.en.f.pronoun = ... | |
| genderTranslator.en.f.reflexivePronoun = ... | |
| genderTranslator.en.m.possessive = ... | |
| genderTranslator.en.m.pronoun = ... | |
| genderTranslator.en.m.reflexivePronoun = ... | |
| genderTranslator.en.o.possessive = ... | |
| genderTranslator.en.o.pronoun = ... | |
| genderTranslator.en.o.reflexivePronoun = ... | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface GenderModifier { | |
| public void visit(GenderWords words); | |
| } | |
| class TranslationGenderModifier implements GenderModifier { | |
| final String prefix; | |
| final String matcher; | |
| public void visit(GenderWords words) { | |
| TranslationEngine e = TranslationEngine.build(Locale.getCurrentLocale()); | |
| words.setPossessive(e.get(prefix + "Possessive")); | |
| words.setReflexivePronoun(e.get(prefix + "ReflexivePronoun")); | |
| words.setPronoun(e.get(prefix + "Pronoun")); | |
| } | |
| public TranslationGenderModifier(String prefix, String matcher) { | |
| this.prefix = prefix; | |
| this.matcher = matcher; | |
| } | |
| } | |
| class MaleGenderModifier implements GenderModifier extends TranslationGenderModifier { | |
| public MaleGenderModifier() { | |
| super("male","m"); | |
| } | |
| } | |
| class FemaleGenderModifier implements GenderModifier extends TranslationGenderModifier { | |
| public FemaleGenderModifier() { | |
| super("female","f"); | |
| } | |
| } | |
| class OtherGenderModifier implements GenderModifier extends TranslationGenderModifier { | |
| public OtherGenderModifier() { | |
| super("other","o"); | |
| } | |
| } | |
| class GenderModifierFactory { | |
| public static GenderModifier build(String gender) { | |
| char g = gender.toLowerCase.charAt(0); // DO WE NEED TO SUPPORT UTF-8? | |
| switch(g) { | |
| case 'm': return new MaleGenderModifier(); | |
| case 'f': return new FemaleGenderModifier(); | |
| case 'o': return new OtherGenderModifier(); | |
| } | |
| } | |
| } | |
| class GenderWords { | |
| ..getters/setters.. | |
| public void genderModifier() { | |
| GenderModifierFactory.build(gender).visit(this); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void genderModifier() { | |
| TranslationEngine e = new TranslationEngine(Locale.getCurrentLocale()); | |
| char g = gender.toLowerCase.charAt(0); // DO WE NEED TO SUPPORT UTF-8? | |
| switch(g) { | |
| case 'm': | |
| possessive = e.get("malePossessive"); | |
| reflexivePronoun = e.get("maleReflexivePronoun"); | |
| pronoun = e.get("malePronoun"); | |
| break; | |
| case 'f': | |
| possessive = e.get("femalePossessive"); | |
| reflexivePronoun = e.get("femaleReflexivePronoun"); | |
| pronoun = e.get("femalePronoun"); | |
| break; | |
| default: | |
| possessive = e.get("otherProssessive"); | |
| reflexivePronoun = e.get("otherReflexivePronoun"); | |
| pronoun = e.get("otherPronoun"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void genderModifier() { | |
| char g = gender.toLowerCase.charAt(0); // DO WE NEED TO SUPPORT UTF-8? | |
| switch(g) { | |
| case 'm': | |
| possessive = "his"; | |
| reflexivePronoun = "him"; | |
| pronoun = "he"; | |
| break; | |
| case 'f': | |
| possessive = "her"; | |
| reflexivePronoun = "her"; | |
| pronoun = "she"; | |
| break; | |
| default: | |
| possessive = "hir"; | |
| reflexivePronoun = "hir"; | |
| pronoun = "ze"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface GenderModifier { | |
| public void visit(GenderWords words); | |
| } | |
| class TranslationGenderModifier implements GenderModifier { | |
| final String prefix; | |
| final String matcher; | |
| public void visit(GenderWords words) { | |
| TranslationEngine e = TranslationEngine.build(Locale.getCurrentLocale()); | |
| words.setPossessive(e.get(prefix + "Possessive")); | |
| words.setReflexivePronoun(e.get(prefix + "ReflexivePronoun")); | |
| words.setPronoun(e.get(prefix + "Pronoun")); | |
| } | |
| public TranslationGenderModifier(String prefix, String matcher) { | |
| this.prefix = prefix; | |
| this.matcher = matcher; | |
| } | |
| } | |
| class GenderModifierFactory { | |
| public static GenderModifier build(String gender) { | |
| char g = gender.toLowerCase.charAt(0); // DO WE NEED TO SUPPORT UTF-8? | |
| switch(g) { | |
| case 'm': return new TranslationGenderModifier("male","m"); | |
| case 'f': return new TranslationGenderModifier("female","f"); | |
| case 'o': return new TranslationGenderModifier("other","f"); | |
| } | |
| } | |
| } | |
| class GenderWords { | |
| ..getters/setters.. | |
| public void genderModifier() { | |
| GenderModifierFactory.build(gender).visit(this); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment