Browse files

Detect language, and use that version of help, if available

  • Loading branch information...
1 parent 4275cc5 commit 639eb6eb112850ea878ab473df40ec5688819088 @deadprogram deadprogram committed Feb 11, 2012
Showing with 39 additions and 30 deletions.
  1. +18 −16 app/models/languages.rb
  2. +5 −5 app/widgets/main.rb
  3. +1 −1 main.rb
  4. +1 −1 public/index.html
  5. +7 −0 public/js/app.js
  6. +7 −7 spec/models/languages_spec.rb
View
34 app/models/languages.rb
@@ -1,24 +1,26 @@
module KidsRuby
- LANGUAGES_SUPPORTED = %w{en}
+ class Language
+ LANGUAGES_SUPPORTED = %w{en}
- class << self
- def system_language
- Qt::Locale.system.name[0..1]
- end
+ class << self
+ def system
+ Qt::Locale.system.name[0..1]
+ end
- def default_language
- 'en'
- end
+ def default
+ 'en'
+ end
- def languages_supported
- LANGUAGES_SUPPORTED
- end
+ def supported
+ LANGUAGES_SUPPORTED
+ end
- def language
- if languages_supported.include?(system_language)
- system_language
- else
- default_language
+ def current
+ if supported.include?(system)
+ system
+ else
+ default
+ end
end
end
end
View
10 app/widgets/main.rb
@@ -9,7 +9,7 @@ class MainWidget < Qt::WebView
alternate_theme "ace/theme/clouds"
signals 'stdInRequested()'
- slots 'rejectStdin()', 'acceptStdin()',
+ slots 'rejectStdin()', 'acceptStdin()', 'QString language()',
'evaluateRuby(QString)', 'stopRuby()', 'runnerFinished(int, QProcess::ExitStatus)',
'setupQtBridge()', 'openRubyFile(const QString&)', 'saveRubyFile(const QString&)',
'QString gets()', 'alert(const QString&)', 'QString ask(const QString&)',
@@ -48,10 +48,6 @@ def version_description
'KidsRuby v' + KidsRuby::VERSION
end
- def language
- KidsRuby.language
- end
-
def keyPressEvent(event)
return false if event.key == Qt::Key_Escape
notify_stdin_event_listeners(event) if @acceptStdin
@@ -60,6 +56,10 @@ def keyPressEvent(event)
private
+ def language
+ KidsRuby::Language.current
+ end
+
def initialize_stdin_connection
Qt::Object.connect(self, SIGNAL("stdInRequested()"),
self, SLOT('acceptStdin()'))
View
2 main.rb
@@ -2,7 +2,7 @@
require 'rubygems'
require 'Qt'
-%w{ frame_writer runner_writer stdin_rejecter version runner turtle }.each do |f|
+%w{ languages frame_writer runner_writer stdin_rejecter version runner turtle }.each do |f|
require File.expand_path(File.dirname(__FILE__) + "/app/models/#{f}.rb")
end
View
2 public/index.html
@@ -57,7 +57,7 @@
</ul>
<div id="help">
- <iframe src="help/en/index.html"></iframe>
+ <iframe id="help-iframe" src="help/en/index.html"></iframe>
</div>
<div id="output">
View
7 public/js/app.js
@@ -203,6 +203,11 @@ function scrollToOutputEnd() {
$('#output').scrollTop(height);
}
+function initHelp() {
+ language = QTApi["language()"]()
+ $("#help-iframe").attr("src", "help/" + language + "/index.html");
+}
+
$(document).ready(function() {
var tabs = $("#tabs").tabs();
$("#tabs").data("mytabs", tabs);
@@ -238,6 +243,8 @@ $(document).ready(function() {
return false;
});
+ initHelp();
+
initTurtle();
selectTab(0); // default to help tab
View
14 spec/models/languages_spec.rb
@@ -3,18 +3,18 @@
describe 'KidsRubyLanguages' do
it "should default to 'en'" do
- KidsRuby.default_language.must_equal 'en'
+ KidsRuby::Language.default.must_equal 'en'
end
it "should not allow unsupported language" do
- KidsRuby.stubs(:system_language).returns('av')
- KidsRuby.language.wont_equal 'av'
- KidsRuby.language.must_equal 'en'
+ KidsRuby::Language.stubs(:system).returns('av')
+ KidsRuby::Language.current.wont_equal 'av'
+ KidsRuby::Language.current.must_equal 'en'
end
it "should allow any supported language" do
- KidsRuby.stubs(:system_language).returns('es')
- KidsRuby.stubs(:languages_supported).returns(['es', 'en', 'ru'])
- KidsRuby.language.must_equal 'es'
+ KidsRuby::Language.stubs(:system).returns('es')
+ KidsRuby::Language.stubs(:supported).returns(['es', 'en', 'ru'])
+ KidsRuby::Language.current.must_equal 'es'
end
end

0 comments on commit 639eb6e

Please sign in to comment.