New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localized Strings #45

Closed
briangbrown opened this Issue Nov 12, 2012 · 41 comments

Comments

Projects
None yet
7 participants
@briangbrown
Contributor

briangbrown commented Nov 12, 2012

The importer and exporter should probably use LanguageHandler to load a strings file and all string references should go through the LanguageHandler to facilitate translation.

$stl_strings = LanguageHandler.new('sketchup-stl.strings')

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 12, 2012

Sounds good.

(Without the globals, of course ;) )

@jimfoltz

This comment has been minimized.

Contributor

jimfoltz commented Nov 14, 2012

I was wondering about this. Currently, any .strings files need to go in the Resources folder for langhandler.rb (via Sketchup.get_resource_path) to find them. Does the built-in .rbz installer support installing to the Resource folder? Will langhandler.rb need to be modified to look in an extension's folder for the .strings file?

In short, how are .strings files going to be handled in an extension like sketchup-stl?

@Aerilius

This comment has been minimized.

Contributor

Aerilius commented Nov 14, 2012

Dan suggested the possibility to pass a full path (of the strings file) to LanguageHandler.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 14, 2012

If that doesn't work we can use the translator class I use from my TT_lib2: http://www.thomthom.net/software/sketchup/tt_lib2/doc/TT/Babelfish.html

@scottlininger

This comment has been minimized.

Contributor

scottlininger commented Nov 14, 2012

RBZ can only install to the Plugins folder at the moment.

We could modify the base langhandler.rb functionality to accept a full path. Perhaps we could prototype it inside this project, then I could take our changes back to the larger SketchUp team to see about getting it rolled into the default SketchUp client install.

Or if we agree that it would be better to figure out a standard for allowing RBZ to install into Resources, we could explore that too.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 14, 2012

Subclass the langhandler?

LanguageHandler.ParseLangFile is the culprit. Though, it looks like one need to copy the entire method into the subclass - even though it's just the first line that needs changing.

(Btw, why is the method names in LanguageHandler constants? (upper capital) )

@scottlininger

This comment has been minimized.

Contributor

scottlininger commented Nov 14, 2012

LanguageHandler was written years and years ago, before there were Ruby naming conventions on the team. Thus the weird capitalization.

Subclassing seems reasonable to me.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 21, 2012

I think I've found an easy way to sub-class LangHandler to correct the path issue without rewriting any of the code.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 21, 2012

@jimfoltz , are you able to merge your changes into upstream? I don't want to implement localisation with pending changes to be merged as I'll be creating global changes.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 21, 2012

Cursed! My little shim didn't work when applied to a sub-class. I think I might just rewrite it from scratch.

@jimfoltz

This comment has been minimized.

Contributor

jimfoltz commented Nov 21, 2012

I think I've found an easy way to sub-class LangHandler to correct the path issue without rewriting any of the code.

Maybe a rewrite under the CommunityExtensions scope would be better? It isn't as if there is a lot to rewrite, or a huge savings to be had by sub-classing.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 21, 2012

I'm currently working on a draft rewrite which cleans up a lot, extends, but provide backwards compatibility with LangHandler.

@jimfoltz

This comment has been minimized.

Contributor

jimfoltz commented Nov 21, 2012

@jimfoltz , are you able to merge your changes into upstream? I don't want to implement localisation with pending changes to be merged as I'll be creating global changes.

Don't wait on me... I don't have a pull request pending and my changes can be reworked easily enough.

git is supposed to be the solution to to these types of development problems. Makes me think we are still not using it optimally.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 22, 2012

I just thought it could perhaps save some manual merges.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

I've implemented localisation: https://github.com/thomthom/sketchup-stl/tree/feature-translator

I wrote a new parse for the string files - it can read the files that LangHandler does, and have aliases that matches the LanguageHandler class so it can be used as a drop in replacement in other projects. I has some extended capabilities as well that should make it easier to read and format the .strings files.

I need to implement localisation of the webdialog before I can push the change.

@Aerilius

This comment has been minimized.

Contributor

Aerilius commented Nov 28, 2012

The parser looks very good! Are you going to do the webdialog localisation in extra files (js), or embed it in the Translator class? (like ae_TextureResizer/Translate.rb: Translate.webdialog(dlg))

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

I'll be cleaning up the parse with better comments so it's easier to work out each step in it. I found it very easy to extend. I implemented the string concat feature in a couple of minutes.

The WebDialog localisation is done by sending a JSON with replacement strings (jQuery selectors as keys) to the webdialog where it performs the replacement. It's done when the DOM is ready so it should be immediate. I use similar technique in Vertex Tools and it's worked well so far. (Though I might need to make adjustments if the JSON becomes too large to transfer - but atm it's nowhere near to be an issue.)

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

Implemented WebDialog translation! :D (Nice to get something done while you wait for a render to complete...)

It'd be nice to be able to see it working in a localized version of SketchUp though...
Andreas, do you run a German SketchUp?

@Aerilius

This comment has been minimized.

Contributor

Aerilius commented Nov 28, 2012

Yes (translating...)

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

Excellent!

@scottlininger is there an easy way to test localisation? Swap locale in SketchUp?

@Aerilius

This comment has been minimized.

Contributor

Aerilius commented Nov 28, 2012

Ha, we have been waiting long for that! I don't know of such an option in SU (or any environment variables that SU would listen to), and even if you intentionally install a foreign language version it will fallback to English on your computer.
Someone in the Help Forum found out that you have to change the operating system locale: https://productforums.google.com/d/msg/sketchup/xsfnZtkWxnQ/0kbVoio235gJ
(The locale can be changed also with a single language license of Windows.)

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

Think there is a thread in the Beta forum - but appeared to be for OSX. Wonder if it was possible to install two versions side by side...

@Aerilius

This comment has been minimized.

Contributor

Aerilius commented Nov 28, 2012

You can install side by side (and then switch symlinks or rename it). But if it detects your system locale is not Chinese, then it falls back to English even if you intentionally wanted to use/test the Chinese version. So any version will show up English except the single one that matches your locale.

@Aerilius

This comment has been minimized.

Contributor

Aerilius commented Nov 28, 2012

One issue is: I first set the folder name to de-DE, but Translator finds it only if it is de (what SketchUp returns as locale). Maybe we could make a fallback.
SketchUp itself also does not have a fallback, so pt-PT users get English because their locale is not exactly pt-BR.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

Yea - it currently matches what LanguageHandler does. So one need to follow the folder naming convention you see in SketchUp's resource folder.

How would the fall-back work? There is no way to get the system locale - just the SketchUp locale. And doesn't SketchUp return a locale code only if it's translated into that locale?

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

When I edit the .strings file in Notepad++ I set the highligher to use C syntax which works well except for the multi.-line strings. Haven't found another language syntax that matches that.

@Aerilius

This comment has been minimized.

Contributor

Aerilius commented Nov 28, 2012

The locale is recognized and the translations all display correctly.

Fixed invalid file in Translator: 10a90fa
German translation: 89c8fca
Some layout adjustments might be necessary. The issue with absolute px positioning is that it sometimes words don't fit (in this case some letters of 'Einheiten' were covered behind the select box). 01547ce

As for a fall back for similar locales, maybe we can do soething with regular expressions and Dir.glob()
I found a code snippet:

language = locale[/^[^\-]+/]
available_files = Dir.entries(stringsdir).find_all{|f|
  File.basename(f)[/^#{locale}/i]
}.concat(Dir.entries(dir).find_all{|f|
  File.basename(f)[/^#{language}/i]
})
return if available_files.empty?
path = File.join(stringsdir, available_files.first)
@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

Nice. Can you send me a pull request so I can merge your changes into my branch?

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

About the fallback - what is it doing?

As I mentioned before, does SketchUp report the locale of anything other than the locales that SketchUp is available in? In which case such fallback would have no effect.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

https://developers.google.com/sketchup/docs/ourdoc/sketchup#get_locale

Sketchup.get_locale
The get_locale method returns the language code for the language SketchUp is running in.

Valid return values include: en-US, fr, it, de, es, ja, ko, zh-CN, zh-TW, pt-BR, nl, ru.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

Not sure if that list is up to date... @scottlininger ?

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

Nice. Can you send me a pull request so I can merge your changes into my branch?

Never mind - I found I could do the pull request myself. :)

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

Should add support for possible Unicode BOM. UTF-8 should be enough, right?

@tylermiller

This comment has been minimized.

tylermiller commented Nov 28, 2012

Hey guys - was just catching up on the dialog and saw the question about
forcing SU to run in a particular language. On Windows, there is a
commandline switch you can use:

sketchup.exe /lang es

where es is the language code (Spanish in this example).

One caveat - There must be the corresponding language folder under the
/Resources sub-folder. One dirty trick I use is to just copy the english
folder into a language that I want to test, then just change the strings
file for the particular plugin I'm using.

Hope that helps,
Tyler

On Wed, Nov 28, 2012 at 8:17 AM, Thomas Thomassen
notifications@github.comwrote:

Should add support for possible Unicode BOM. UTF-8 should be enough, right?


Reply to this email directly or view it on GitHubhttps://github.com//issues/45#issuecomment-10806099.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 28, 2012

That's great Tyler! Thanks for the heads up!

@Aerilius - can you zip and send me the German resource folder? I'd like to try this.

@Aerilius

This comment has been minimized.

Contributor

Aerilius commented Nov 28, 2012

It works!
@tyler: Thanks!! We have urged the support guys on this question so much, but they cannot keep up with your magic! Though command line parameters aren't officially supported, can we use them to solve language problems in the forum?

@thomthom: I'll send you some languages. Some time ago I got errors when mixing language files, maybe when code pages didn't match.

@tylermiller

This comment has been minimized.

tylermiller commented Nov 28, 2012

Aerilius -

Feel free to discuss the /lang switch on the forums. If it is useful for
our developer partners, I'm all for sharing it.

-Tyler

On Wed, Nov 28, 2012 at 4:10 PM, Aerilius notifications@github.com wrote:

It works!
@tyler https://github.com/Tyler: Thanks!! We have urged the support
guys on this question so much, but they cannot keep up with your magic!
Though command line parameters aren't officially supported, can we use them
to solve language problems in the forum?

@thomthom https://github.com/thomthom: I'll send you some languages.
Some time ago I got errors when mixing language files, maybe when code
pages didn't match.


Reply to this email directly or view it on GitHubhttps://github.com//issues/45#issuecomment-10827495.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 29, 2012

@tyler: This is working great! 👍 👍
It would be nice if there was a download for developers so they (we) could download all the language packs in one package for testing.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 29, 2012

Realized I'd previously asked for how Sketchup.get_localeworked - the reply was:

the method works in the following way, if the default OS language is different than English the method checks the resource folder in the SU install and see if the default OS language has a correspondent resource file, in which case the OS language is returned, otherwise the default en-US is returned.

@tyler

This comment has been minimized.

tyler commented Nov 29, 2012

Hey guys. You ought to know that when you use @-name it notifies the person with that GitHub username. To get your intended effect, you'd want to use "@tylermiller". As it is, I keep getting emails from this thread.

@thomthom

This comment has been minimized.

Member

thomthom commented Nov 29, 2012

Ah! Gotcha! 👍 Sorry!

@ghost ghost assigned thomthom Nov 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment