awesome_translations 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b375c005d186492da432ff61ee765d1cec23561d
4
- data.tar.gz: 880aaef8a675d36e7564b83275ca9f2515f2a08c
3
+ metadata.gz: 841a4232003732fc8e30b6193b46f31604a51086
4
+ data.tar.gz: 798320a600a7b4aaad1f39910e5f1dee898f2b57
5
5
  SHA512:
6
- metadata.gz: 6e7802f5bb02f054029758938701f17ce82bd43e38011b3c560d8fd76dd6be8b646f484233f190fd1a353988607877ffee9dd0d70b789760b51fed823ce28f43
7
- data.tar.gz: 0a5ca541fdc9087642ed5011047609b1c73a4598aee6587129efe401de0543163acbda928903bb238523ba08fdf52f399c857a02063be808c348000c94b58ed9
6
+ metadata.gz: 227e2b2decb2056fc30351cc62f164c6f8ae61572e4934ecdaf23f4a94601b2e9b906da82a2874b174540ac8a3ed8142dcfd7e6a6a30354edb301ddf2bbb2a1a
7
+ data.tar.gz: db7f8e1019e5086cb9f0a8a45ee6809e579394b716903afdef196026766685540c21d8ad9488be9604a15510e3fb690f878ff3664688b51c8f4b40d16418b835
data/README.md CHANGED
@@ -20,6 +20,19 @@ Insert this into your "routes.rb" file:
20
20
  mount AwesomeTranslations::Engine => "/awesome_translations" if Rails.env.development?
21
21
  ```
22
22
 
23
+ ## Translations under controllers and models
24
+
25
+ If you want to do translations from your models or controllers, you will need to add this to a new initializer file under "config/initializers/awesome_translations.rb"
26
+
27
+ ```ruby
28
+ AwesomeTranslations.load_object_extensions
29
+ ```
30
+
31
+ You will also need to modify the line in your Gemfile a bit:
32
+ ```ruby
33
+ gem 'awesome_translations'
34
+ ```
35
+
23
36
  ## Translating your application
24
37
 
25
38
  Start a Rails server for your project and go to the namespace called something like "http://localhost:3000/awesome_translations". Start translating your app through the webinterface.
@@ -0,0 +1,43 @@
1
+ class AwesomeTranslations::GlobalTranslator
2
+ def self.translate(key, args, &blk)
3
+ if key.is_a?(String) && key.start_with?(".")
4
+ caller_number = args[:caller_number] || 0
5
+
6
+ # Removed any helpful appended input to filepath from stacktrace.
7
+ if match = caller[caller_number].match(/\A(.+):(\d+):/)
8
+ previous_file = match[1]
9
+ else
10
+ raise "Could not get previous file name from: #{caller[0]}"
11
+ end
12
+
13
+ # Remove any Rails root.
14
+ removed_root = false
15
+ AwesomeTranslations::ModelInspector.engines.each do |engine|
16
+ root = engine.root.to_s
17
+
18
+ if previous_file.starts_with?(root)
19
+ previous_file = previous_file.gsub(/\A#{Regexp.escape(root)}\//, "")
20
+ removed_root = true
21
+ break
22
+ end
23
+ end
24
+
25
+ dir = File.dirname(previous_file)
26
+ dir = dir.gsub(/\A#{Regexp.escape(Rails.root.to_s)}\//, "")
27
+ dir = dir.gsub(/\Aapp\//, "") if dir.starts_with?("app/")
28
+
29
+ file = File.basename(previous_file, File.extname(previous_file))
30
+
31
+ translation_key = dir
32
+ translation_key = translation_key.gsub(/\Aapp\//, "")
33
+ translation_key << "/#{file}"
34
+ translation_key.gsub!("/", ".")
35
+ translation_key << key
36
+
37
+ # Change key to full path.
38
+ key = translation_key
39
+ end
40
+
41
+ I18n.t(key, *args[:translation_args], &blk)
42
+ end
43
+ end
@@ -1,41 +1,5 @@
1
1
  module AwesomeTranslations::ObjectExtensions
2
2
  def t(key, *args, &blk)
3
- if key.is_a?(String) && key.start_with?(".")
4
- # Removed any helpful appended input to filepath from stacktrace.
5
- if match = caller[0].match(/\A(.+):(\d+):/)
6
- previous_file = match[1]
7
- else
8
- raise "Could not get previous file name from: #{caller[0]}"
9
- end
10
-
11
- # Remove any Rails root.
12
- removed_root = false
13
- AwesomeTranslations::ModelInspector.engines.each do |engine|
14
- root = engine.root.to_s
15
-
16
- if previous_file.starts_with?(root)
17
- previous_file = previous_file.gsub(/\A#{Regexp.escape(root)}\//, "")
18
- removed_root = true
19
- break
20
- end
21
- end
22
-
23
- dir = File.dirname(previous_file)
24
- dir = dir.gsub(/\A#{Regexp.escape(Rails.root.to_s)}\//, "")
25
- dir = dir.gsub(/\Aapp\//, "") if dir.starts_with?("app/")
26
-
27
- file = File.basename(previous_file, File.extname(previous_file))
28
-
29
- translation_key = dir
30
- translation_key = translation_key.gsub(/\Aapp\//, "")
31
- translation_key << "/#{file}"
32
- translation_key.gsub!("/", ".")
33
- translation_key << key
34
-
35
- # Change key to full path.
36
- key = translation_key
37
- end
38
-
39
- I18n.t(key, *args, &blk)
3
+ AwesomeTranslations::GlobalTranslator.translate(key, caller_number: 1, translation_args: args, &blk)
40
4
  end
41
5
  end
@@ -1,3 +1,3 @@
1
1
  module AwesomeTranslations
2
- VERSION = "0.0.7"
2
+ VERSION = '0.0.8'
3
3
  end
@@ -4,11 +4,14 @@ require "array_enumerator"
4
4
  require "jquery-rails"
5
5
 
6
6
  module AwesomeTranslations
7
- autoload :Config, "#{File.dirname(__FILE__)}/awesome_translations/config"
8
- autoload :ErbInspector, "#{File.dirname(__FILE__)}/awesome_translations/erb_inspector"
9
- autoload :Handlers, "#{File.dirname(__FILE__)}/awesome_translations/handlers"
10
- autoload :ObjectExtensions, "awesome_translations/object_extensions"
11
- autoload :ModelInspector, "awesome_translations/model_inspector"
7
+ path = "#{File.dirname(__FILE__)}/awesome_translations"
8
+
9
+ autoload :Config, "#{path}/config"
10
+ autoload :ErbInspector, "#{path}/erb_inspector"
11
+ autoload :GlobalTranslator, "#{path}/global_translator"
12
+ autoload :Handlers, "#{path}/handlers"
13
+ autoload :ObjectExtensions, "#{path}/object_extensions"
14
+ autoload :ModelInspector, "#{path}/model_inspector"
12
15
 
13
16
  def self.config
14
17
  @config ||= AwesomeTranslations::Config.new
@@ -591,3 +591,236 @@ Completed 302 Found in 8ms (ActiveRecord: 0.0ms)
591
591
   (0.0ms) rollback transaction
592
592
   (0.0ms) begin transaction
593
593
   (0.0ms) rollback transaction
594
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
595
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
596
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
597
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
598
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
599
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
600
+  (0.1ms) begin transaction
601
+  (0.1ms) SAVEPOINT active_record_1
602
+ User Exists (0.4ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'rbutler@shuffledrive.com' LIMIT 1
603
+ SQL (2.6ms) INSERT INTO "users" ("age", "email", "password") VALUES (?, ?, ?) [["age", 5], ["email", "rbutler@shuffledrive.com"], ["password", "curabitur at"]]
604
+  (0.0ms) RELEASE SAVEPOINT active_record_1
605
+ Processing by UsersController#index as HTML
606
+ User Load (0.1ms) SELECT "users".* FROM "users"
607
+ Rendered users/index.html.haml within layouts/application (12.5ms)
608
+ Completed 200 OK in 48ms (Views: 47.8ms | ActiveRecord: 0.1ms)
609
+  (0.6ms) rollback transaction
610
+  (0.0ms) begin transaction
611
+  (0.1ms) rollback transaction
612
+  (0.0ms) begin transaction
613
+  (0.0ms) rollback transaction
614
+  (0.0ms) begin transaction
615
+  (0.0ms) rollback transaction
616
+  (0.1ms) begin transaction
617
+ Processing by AwesomeTranslations::HandlersController#index as HTML
618
+ Completed 200 OK in 205ms (Views: 204.7ms | ActiveRecord: 0.0ms)
619
+  (0.1ms) rollback transaction
620
+  (0.1ms) begin transaction
621
+ Processing by AwesomeTranslations::HandlersController#show as HTML
622
+ Parameters: {"id"=>"model_handler"}
623
+ Completed 200 OK in 10ms (Views: 10.1ms | ActiveRecord: 0.0ms)
624
+  (0.1ms) rollback transaction
625
+  (0.0ms) begin transaction
626
+  (0.1ms) rollback transaction
627
+  (0.1ms) begin transaction
628
+  (0.1ms) rollback transaction
629
+  (0.1ms) begin transaction
630
+  (0.1ms) rollback transaction
631
+  (0.1ms) begin transaction
632
+  (0.1ms) rollback transaction
633
+  (0.1ms) begin transaction
634
+  (0.1ms) rollback transaction
635
+  (0.0ms) begin transaction
636
+  (0.0ms) rollback transaction
637
+  (0.1ms) begin transaction
638
+  (0.0ms) rollback transaction
639
+  (0.0ms) begin transaction
640
+  (0.0ms) rollback transaction
641
+  (0.0ms) begin transaction
642
+  (0.0ms) rollback transaction
643
+  (0.0ms) begin transaction
644
+  (0.0ms) rollback transaction
645
+  (0.0ms) begin transaction
646
+  (0.0ms) rollback transaction
647
+  (0.0ms) begin transaction
648
+  (0.0ms) rollback transaction
649
+  (0.0ms) begin transaction
650
+  (0.0ms) rollback transaction
651
+  (0.0ms) begin transaction
652
+  (0.0ms) rollback transaction
653
+  (0.0ms) begin transaction
654
+  (0.0ms) rollback transaction
655
+  (0.0ms) begin transaction
656
+  (0.0ms) rollback transaction
657
+  (0.0ms) begin transaction
658
+  (0.1ms) rollback transaction
659
+  (0.0ms) begin transaction
660
+  (0.1ms) rollback transaction
661
+  (0.0ms) begin transaction
662
+  (0.1ms) rollback transaction
663
+  (0.0ms) begin transaction
664
+  (0.1ms) rollback transaction
665
+  (0.0ms) begin transaction
666
+  (0.1ms) rollback transaction
667
+  (0.0ms) begin transaction
668
+ Processing by AwesomeTranslations::GroupsController#update as HTML
669
+ Parameters: {"handler_id"=>"model_handler", "id"=>"User", "t"=>{"activerecord.attributes.user.password"=>"[FILTERED]"}}
670
+ Redirected to http://test.host/handlers/model_handler/groups/User
671
+ Completed 302 Found in 5ms (ActiveRecord: 0.0ms)
672
+  (0.1ms) rollback transaction
673
+  (0.0ms) begin transaction
674
+ Processing by AwesomeTranslations::GroupsController#update as HTML
675
+ Parameters: {"handler_id"=>"model_handler", "id"=>"Role", "t"=>{"activerecord.attributes.role.role"=>{"da"=>"Rolle", "de"=>"Die type", "en"=>"Role"}}}
676
+ Redirected to http://test.host/handlers/model_handler/groups/Role
677
+ Completed 302 Found in 8ms (ActiveRecord: 0.0ms)
678
+  (0.1ms) rollback transaction
679
+  (0.0ms) begin transaction
680
+  (0.1ms) rollback transaction
681
+  (0.0ms) begin transaction
682
+  (0.1ms) rollback transaction
683
+  (0.0ms) begin transaction
684
+  (0.1ms) rollback transaction
685
+  (0.0ms) begin transaction
686
+  (0.1ms) rollback transaction
687
+  (0.0ms) begin transaction
688
+  (0.1ms) rollback transaction
689
+  (0.1ms) begin transaction
690
+  (0.1ms) rollback transaction
691
+  (0.1ms) begin transaction
692
+  (0.1ms) rollback transaction
693
+  (0.0ms) begin transaction
694
+  (0.1ms) rollback transaction
695
+  (0.0ms) begin transaction
696
+  (0.1ms) rollback transaction
697
+  (0.0ms) begin transaction
698
+  (0.1ms) rollback transaction
699
+  (0.0ms) begin transaction
700
+  (0.0ms) rollback transaction
701
+  (0.0ms) begin transaction
702
+  (0.0ms) rollback transaction
703
+  (0.0ms) begin transaction
704
+  (0.0ms) rollback transaction
705
+  (0.0ms) begin transaction
706
+  (0.1ms) rollback transaction
707
+  (0.0ms) begin transaction
708
+  (0.1ms) rollback transaction
709
+  (0.0ms) begin transaction
710
+  (0.0ms) rollback transaction
711
+  (0.0ms) begin transaction
712
+  (0.0ms) rollback transaction
713
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
714
+  (0.1ms) begin transaction
715
+  (0.0ms) rollback transaction
716
+  (0.0ms) begin transaction
717
+  (0.1ms) SAVEPOINT active_record_1
718
+ User Exists (0.1ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'sramos@eabox.name' LIMIT 1
719
+ SQL (2.1ms) INSERT INTO "users" ("age", "email", "password") VALUES (?, ?, ?) [["age", 10], ["email", "sramos@eabox.name"], ["password", "in hac"]]
720
+  (0.1ms) RELEASE SAVEPOINT active_record_1
721
+ Processing by UsersController#index as HTML
722
+ User Load (0.1ms) SELECT "users".* FROM "users"
723
+ Rendered users/index.html.haml within layouts/application (12.1ms)
724
+ Completed 200 OK in 29ms (Views: 28.0ms | ActiveRecord: 0.1ms)
725
+  (0.4ms) rollback transaction
726
+  (0.1ms) begin transaction
727
+ Processing by AwesomeTranslations::GroupsController#update as HTML
728
+ Parameters: {"handler_id"=>"model_handler", "id"=>"User", "t"=>{"activerecord.attributes.user.password"=>"[FILTERED]"}}
729
+ Redirected to http://test.host/handlers/model_handler/groups/User
730
+ Completed 302 Found in 8ms (ActiveRecord: 0.0ms)
731
+  (0.1ms) rollback transaction
732
+  (0.1ms) begin transaction
733
+ Processing by AwesomeTranslations::GroupsController#update as HTML
734
+ Parameters: {"handler_id"=>"model_handler", "id"=>"Role", "t"=>{"activerecord.attributes.role.role"=>{"da"=>"Rolle", "de"=>"Die type", "en"=>"Role"}}}
735
+ Redirected to http://test.host/handlers/model_handler/groups/Role
736
+ Completed 302 Found in 9ms (ActiveRecord: 0.0ms)
737
+  (0.1ms) rollback transaction
738
+  (0.1ms) begin transaction
739
+  (0.1ms) rollback transaction
740
+  (0.0ms) begin transaction
741
+  (0.1ms) rollback transaction
742
+  (0.1ms) begin transaction
743
+  (0.1ms) rollback transaction
744
+  (0.0ms) begin transaction
745
+ Processing by AwesomeTranslations::HandlersController#index as HTML
746
+ Completed 200 OK in 12ms (Views: 11.4ms | ActiveRecord: 0.0ms)
747
+  (0.1ms) rollback transaction
748
+  (0.0ms) begin transaction
749
+ Processing by AwesomeTranslations::HandlersController#show as HTML
750
+ Parameters: {"id"=>"model_handler"}
751
+ Completed 200 OK in 21ms (Views: 20.8ms | ActiveRecord: 0.0ms)
752
+  (0.1ms) rollback transaction
753
+  (0.0ms) begin transaction
754
+  (0.0ms) rollback transaction
755
+  (0.0ms) begin transaction
756
+  (0.0ms) rollback transaction
757
+  (0.0ms) begin transaction
758
+  (0.0ms) rollback transaction
759
+  (0.0ms) begin transaction
760
+  (0.1ms) rollback transaction
761
+  (0.0ms) begin transaction
762
+  (0.0ms) rollback transaction
763
+  (0.0ms) begin transaction
764
+  (0.0ms) rollback transaction
765
+  (0.0ms) begin transaction
766
+  (0.0ms) rollback transaction
767
+  (0.0ms) begin transaction
768
+  (0.0ms) rollback transaction
769
+  (0.0ms) begin transaction
770
+  (0.1ms) rollback transaction
771
+  (0.0ms) begin transaction
772
+  (0.1ms) rollback transaction
773
+  (0.0ms) begin transaction
774
+  (0.0ms) rollback transaction
775
+  (0.0ms) begin transaction
776
+  (0.1ms) rollback transaction
777
+  (0.0ms) begin transaction
778
+  (0.0ms) rollback transaction
779
+  (0.0ms) begin transaction
780
+  (0.1ms) rollback transaction
781
+  (0.1ms) begin transaction
782
+  (0.1ms) rollback transaction
783
+  (0.1ms) begin transaction
784
+  (0.1ms) rollback transaction
785
+  (0.0ms) begin transaction
786
+  (0.0ms) rollback transaction
787
+  (0.0ms) begin transaction
788
+  (0.0ms) rollback transaction
789
+  (0.0ms) begin transaction
790
+  (0.0ms) rollback transaction
791
+  (0.0ms) begin transaction
792
+  (0.0ms) rollback transaction
793
+  (0.0ms) begin transaction
794
+  (0.0ms) rollback transaction
795
+  (0.0ms) begin transaction
796
+  (0.0ms) rollback transaction
797
+  (0.0ms) begin transaction
798
+  (0.1ms) rollback transaction
799
+  (0.0ms) begin transaction
800
+  (0.0ms) rollback transaction
801
+  (0.0ms) begin transaction
802
+  (0.0ms) rollback transaction
803
+  (0.0ms) begin transaction
804
+  (0.0ms) rollback transaction
805
+  (0.0ms) begin transaction
806
+  (0.1ms) rollback transaction
807
+  (0.0ms) begin transaction
808
+  (0.0ms) rollback transaction
809
+  (0.0ms) begin transaction
810
+  (0.1ms) rollback transaction
811
+  (0.0ms) begin transaction
812
+  (0.1ms) rollback transaction
813
+  (0.0ms) begin transaction
814
+  (0.1ms) rollback transaction
815
+  (0.0ms) begin transaction
816
+  (0.1ms) rollback transaction
817
+  (0.0ms) begin transaction
818
+  (0.1ms) rollback transaction
819
+  (0.0ms) begin transaction
820
+  (0.1ms) rollback transaction
821
+  (0.0ms) begin transaction
822
+  (0.1ms) rollback transaction
823
+  (0.0ms) begin transaction
824
+  (0.1ms) rollback transaction
825
+  (0.1ms) begin transaction
826
+  (0.1ms) rollback transaction
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_translations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-06 00:00:00.000000000 Z
11
+ date: 2015-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -212,6 +212,7 @@ files:
212
212
  - lib/awesome_translations/erb_inspector.rb
213
213
  - lib/awesome_translations/erb_inspector/file_inspector.rb
214
214
  - lib/awesome_translations/erb_inspector/translation_inspector.rb
215
+ - lib/awesome_translations/global_translator.rb
215
216
  - lib/awesome_translations/handlers.rb
216
217
  - lib/awesome_translations/handlers/base_handler.rb
217
218
  - lib/awesome_translations/handlers/erb_handler.rb