Page 1 of 1

Need for language library?

PostPosted: 02 Apr 2013, 14:47
by Max mtg
http://svn.slightlymagic.net/websvn/dif ... &peg=20728

I was looking at all that beautiful string builders, and realzied that if we always build such pretty texts, we'll either copy-paste hundreds of lines or write a special library to perform common tasks.

1. Join homogeneous parts of the sentence.
Code: Select all
        final StringBuilder fetcherSB = new StringBuilder();
        for (int i = 0; i < fetchers.size(); i++) {
            fetcherSB.append(fetchers.get(i).getName());
            fetcherSB.append((i + 2) == fetchers.size() ? " and " : (i + 1) == fetchers.size() ? "" : ", ");
        }
        final String fetcherNames = fetcherSB.toString();
2. Verbs conjunction
Code: Select all
sb.append(" search").append(choosers.size() > 1 ? " " : "es ");
3. Possessive pronouns
Code: Select all
        String fetchPlayer = fetcherNames;
        if (chooserNames.equals(fetcherNames)) {
            fetchPlayer = fetchers.size() > 1 ? "their" : "his/her";
        }
The list is yet to be continued.

Let me name advantages of use of a library: less duplicate code, easier localization to different languages - a single change of rules for text compisition for italian or whatever, will be better than any action on currently scattered texts.
Disadvantages: more complicated texts composition (one will have to look for a method for propper conjuction of lexical forms instead of just typing the strings),

This will be effective only if every developer adopts the system.

Re: Need for language library?

PostPosted: 03 Apr 2013, 11:54
by Max mtg
Looks like noone is interested. It's a pity to see the repeating codes, but we really have more important things to do, let's leave this subject alone for now.

Re: Need for language library?

PostPosted: 03 Apr 2013, 12:00
by moomarc
Max mtg wrote:Looks like noone is interested. It's a pity to see the repeating codes, but we really have more important things to do, let's leave this subject alone for now.
I don't think that noone's interested, just that nobody with the necessary knowledge has time to commit to this while there's so many other bits that need work. It would be great to have a language library that makes localization easier, but its a huge undertaking (or seems that way to me at least) for a relatively small reward, and on parts of the code that, for now, do what they're supposed to. This is obviously easier for the first language English speakers to pass over though, and I do think it should probably happen some time in the future.

Re: Need for language library?

PostPosted: 03 Apr 2013, 12:17
by friarsol
Yea I think that's the hardest thing for most of the native English speakers. Forge is already in my spoken tongue, so the gain for me is pretty thin. Magic is a game where the official language is English. Sure they may print cards in different languages, but all Oracle text is in English and all the Official Rules text are in English.

So I can either spend time trying to get new ability features working like I do now with already limited time commitment, or I could spend time trying to setup hooks for translations I'll never see. While I think the idea is fine, things I don't gain personal benefit from I have a hard time "buying in" to that feature.

Re: Need for language library?

PostPosted: 03 Apr 2013, 12:34
by Max mtg
@Sol, it's not about translation (easier translation is a side effect), it's about elimination of numberles lines that you make vers and numbers conjunction.

The library's aim is to fight this kind of pasta:

sb.(player == Singletons.getControl().getLocalPlayer() ? "You" : p.toString()).append(" ").append("sacrifice").append(player == Singletons.getControl().getLocalPlayer() ? "" : "s").append(" ").append(list.size() == 1 ? "a" : "").append( list.size() == 1 && (new char[]{'aeiou'}).indexOf(list.get(0).toString().charAt(0)) >= 0 ? "n" : "").append(" ").append(StringUtils.join(list, ", "))


That produces nice "You sacrifice an artifact", "Amantha sacrifices a creature", "Mario sacrifices Tarmogoyf, Bottle Gnomes"
but is absolutelly unreadable.

Re: Need for language library?

PostPosted: 03 Apr 2013, 14:03
by friarsol
Max mtg wrote:@Sol, it's not about translation (easier translation is a side effect), it's about elimination of numberles lines that you make vers and numbers conjunction.
Obviously if you write terribly obfuscated code it'll be hard to read. And if you have a few if statements to try to grammar proof things, and make the code easier to read, you'll have a little bit of code duplication.

Put it up on the issue tracker, and let it sit in the back of people's minds for a bit. Maybe someone who lives in that code and is willing to do that task will get motivated and be up for doing it at some point in the future.

Re: Need for language library?

PostPosted: 03 Apr 2013, 14:22
by Max mtg
Haven't seen the ugly tracker for long and I feel absolutelly no guilt about it.
I'll just leave this topic hanging here to attract some attention.

As for my personal position - I can tolerate the code duplications in text builders, while there are enough things to improve in game core... and then multiplayer awaits and then web-client and jogl-based 3D client to be implemented.
I also don't need translation of Forge, because there are more valuable things to do, and my English is good enough to play Magic without a dictionary.

Yet every day looking at commit logs, I notice how certain things could be done better. I started this topic to share that kind of ideas.