imgtools/imaker/buildrom_plugins/localise_all_resources.pm
changeset 607 378360dbbdba
parent 596 9f25be3da657
equal deleted inserted replaced
591:22486c9c7b15 607:378360dbbdba
    11 #
    11 #
    12 # Contributors:
    12 # Contributors:
    13 #
    13 #
    14 # Description:
    14 # Description:
    15 # Adds a LOCALISE macro that enables configuration of localised files.
    15 # Adds a LOCALISE macro that enables configuration of localised files.
    16 # The localised language selection is done with a ADD_LANGUAGE macro.
    16 # The localised language selection is done with a LANGUAGE_CODE macro.
    17 #
    17 #
    18 
    18 
    19 
    19 
    20 
    20 
    21 ###############################################################################
    21 ###############################################################################
    24 #   type=LOCALISE(source, target[, languages])
    24 #   type=LOCALISE(source, target[, languages])
    25 #   source => the source file. The section that needs to be localised should be marked with ??.
    25 #   source => the source file. The section that needs to be localised should be marked with ??.
    26 #   target => the target file. The section that needs to be localised should be marked with ??.
    26 #   target => the target file. The section that needs to be localised should be marked with ??.
    27 #   languages => a space delimited list of language codes
    27 #   languages => a space delimited list of language codes
    28 #
    28 #
    29 # Syntax: ADD_LANGUAGE
    29 # Syntax: LANGUAGE_CODE
    30 #   ADD_LANGUAGE lang
    30 #   LANGUAGE_CODE lang
    31 #
    31 #
    32 # Example:
    32 # Example:
    33 # Add languages
    33 # Add languages
    34 # ADD_LANGUAGE 01
    34 # LANGUAGE_CODE 01
    35 # ADD_LANGUAGE 02
    35 # LANGUAGE_CODE 02
    36 # ADD_LANGUAGE 03
    36 # LANGUAGE_CODE 03
    37 #
    37 #
    38 # Use Case 1:
    38 # Use Case 1:
    39 # Localises a App resoure file.
    39 # Localises a App resoure file.
    40 #   data=LOCALISE(APP_RESOURCE_DIR\App.r??, RESOURCE_DIR\app.r??)
    40 #   data=LOCALISE(APP_RESOURCE_DIR\App.r??, RESOURCE_DIR\app.r??)
    41 # Output:
    41 # Output:
    43 #   data=APP_RESOURCE_DIR\App.r02 RESOURCE_DIR\app.r02
    43 #   data=APP_RESOURCE_DIR\App.r02 RESOURCE_DIR\app.r02
    44 #   data=APP_RESOURCE_DIR\App.r03 RESOURCE_DIR\app.r03
    44 #   data=APP_RESOURCE_DIR\App.r03 RESOURCE_DIR\app.r03
    45 #
    45 #
    46 # Use Case 2:
    46 # Use Case 2:
    47 # Localise all resource files under a section
    47 # Localise all resource files under a section
    48 # ADD_LANGUAGE 01
    48 # LANGUAGE_CODE 01
    49 # ADD_LANGUAGE 02
    49 # LANGUAGE_CODE 02
    50 # ADD_LANGUAGE 03
    50 # LANGUAGE_CODE 03
    51 #
    51 #
    52 # LOCALISE_ALL_RESOURCES_BEGIN
    52 # LOCALISE_ALL_RESOURCES_BEGIN
    53 # // All resource files will be localised
    53 # // All resource files will be localised
    54 # data=APP_RESOURCE_DIR\App.rsc RESOURCE_DIR\app.rsc
    54 # data=APP_RESOURCE_DIR\App.rsc RESOURCE_DIR\app.rsc
    55 # data=APP_RESOURCE_DIR\App2.rsc RESOURCE_DIR\app2.rsc
    55 # data=APP_RESOURCE_DIR\App2.rsc RESOURCE_DIR\app2.rsc
    61 #   data=APP_RESOURCE_DIR\App.r01 RESOURCE_DIR\app.r01
    61 #   data=APP_RESOURCE_DIR\App.r01 RESOURCE_DIR\app.r01
    62 #   data=APP_RESOURCE_DIR\App.r02 RESOURCE_DIR\app.r02
    62 #   data=APP_RESOURCE_DIR\App.r02 RESOURCE_DIR\app.r02
    63 #   data=APP_RESOURCE_DIR\App.r03 RESOURCE_DIR\app.r03
    63 #   data=APP_RESOURCE_DIR\App.r03 RESOURCE_DIR\app.r03
    64 #
    64 #
    65 ###############################################################################
    65 ###############################################################################
    66 
       
    67 #
       
    68 # Version 4
       
    69 # Path corrections to widget support.
       
    70 #
       
    71 # Version 3
       
    72 # Support for Idle widgets.
       
    73 #
       
    74 # Version 2
       
    75 # Localises also *.hlp to *.h%s.
       
    76 #
       
    77 # Version 1
       
    78 # Initial version.
       
    79 
    66 
    80 
    67 
    81 package localise_all_resources;
    68 package localise_all_resources;
    82 use strict;
    69 use strict;
    83 
    70 
   164       # resource files .rsc
   151       # resource files .rsc
   165       if ( is_resource_entry($line) )
   152       if ( is_resource_entry($line) )
   166       {
   153       {
   167         # match data/file=foobar.rsc resource/foobar.rsc
   154         # match data/file=foobar.rsc resource/foobar.rsc
   168         $line = create_localise_entry_from_resource($line);
   155         $line = create_localise_entry_from_resource($line);
       
   156         push @newobydata, "$line\n";
       
   157         next;
       
   158       }
       
   159       # localise all qm files inside the localise_all_resources section
       
   160       # qt resource files .ts
       
   161       if ( is_qt_resource_entry($line) )
       
   162       {
       
   163         # match data/file=foobar.qm resource/foobar.qm
       
   164         $line = create_localise_entry_from_qt_resource($line);
   169         push @newobydata, "$line\n";
   165         push @newobydata, "$line\n";
   170         next;
   166         next;
   171       }
   167       }
   172       # help files .hlp
   168       # help files .hlp
   173       if ( is_help_entry_hlp($line) )
   169       if ( is_help_entry_hlp($line) )
   260     return 1;
   256     return 1;
   261   }
   257   }
   262   return 0;
   258   return 0;
   263 }
   259 }
   264 
   260 
       
   261 sub is_qt_resource_entry($)
       
   262 {
       
   263   my $entry = shift;
       
   264   my $type = get_type_from_entry($entry);
       
   265   my $source = get_source_from_entry($entry);
       
   266   my $target = get_target_from_entry($entry);
       
   267   if ($source =~ m/\.qm[\"|\']?$/i &&
       
   268       $target =~ m/\.qm[\"|\']?$/i )
       
   269   {
       
   270     return 1;
       
   271   }
       
   272   return 0;
       
   273 }
   265 #
   274 #
   266 # match
   275 # match
   267 sub is_help_entry_xhtml($)
   276 sub is_help_entry_xhtml($)
   268 {
   277 {
   269   my $entry = shift;
   278   my $entry = shift;
   270   my $type = get_type_from_entry($entry);
   279   my $type = get_type_from_entry($entry);
   271   my $source = get_source_from_entry($entry);
   280   my $source = get_source_from_entry($entry);
   272   my $target = get_target_from_entry($entry);
   281   my $target = get_target_from_entry($entry);
   273   if ($source =~ m/\\01\\/i &&
   282   if ($source =~ m/[\/\\]01[\/\\]/i &&
   274       $target =~ m/\\01\\/i )
   283       $target =~ m/[\/\\]01[\/\\]/i )
   275   {
   284   {
   276     return 1;
   285     return 1;
   277   }
   286   }
   278   return 0;
   287   return 0;
   279 }
   288 }
   299 {
   308 {
   300   my $entry = shift;
   309   my $entry = shift;
   301   my $type = get_type_from_entry($entry);
   310   my $type = get_type_from_entry($entry);
   302   my $source = get_source_from_entry($entry);
   311   my $source = get_source_from_entry($entry);
   303   my $target = get_target_from_entry($entry);
   312   my $target = get_target_from_entry($entry);
   304   if (($source =~ m/\\01\\.*\.dtd/i &&
   313   if (($source =~ m/[\/\\]01[\/\\].*\.dtd/i &&
   305       $target =~ m/\\01\\.*\.dtd/i ) ||
   314       $target =~ m/[\/\\]01[\/\\].*\.dtd/i ) ||
   306     ($source =~ m/\\00\\.*\.dtd/i &&
   315     ($source =~ m/[\/\\]00[\/\\].*\.dtd/i &&
   307       $target =~ m/\\00\\.*\.dtd/i ))
   316       $target =~ m/[\/\\]00[\/\\].*\.dtd/i ))
   308   {
   317   {
   309     return 1;
   318     return 1;
   310   }
   319   }
   311   return 0;
   320   return 0;
   312 }
   321 }
   388   $target =~ s/\.rsc/\.r%s/i;
   397   $target =~ s/\.rsc/\.r%s/i;
   389   #print "create_localise_entry_from_resource: $source\n";
   398   #print "create_localise_entry_from_resource: $source\n";
   390   return "$type=LOCALISE($source, $target)";
   399   return "$type=LOCALISE($source, $target)";
   391 }
   400 }
   392 
   401 
       
   402 # create localise entry from qt resource entry
       
   403 sub create_localise_entry_from_qt_resource($)
       
   404 {
       
   405   my $entry = shift;
       
   406   my $type = get_type_from_entry($entry);
       
   407   my $source = get_source_from_entry($entry);
       
   408   my $target = get_target_from_entry($entry);
       
   409   #convert the .qm to _xx.qm
       
   410   $source =~ s/\.qm/\_%s.qm/i;
       
   411   $target =~ s/\.qm/\_%s.qm/i;
       
   412   #print "create_localise_entry_from_resource: $source\n";
       
   413   return "$type=LOCALISE($source, $target)";
       
   414 }
       
   415 
   393 # create localise entry from resource entry
   416 # create localise entry from resource entry
   394 sub create_localise_entry_from_help($)
   417 sub create_localise_entry_from_help($)
   395 {
   418 {
   396   my $entry = shift;
   419   my $entry = shift;
   397   my $type = get_type_from_entry($entry);
   420   my $type = get_type_from_entry($entry);
   398   my $source = get_source_from_entry($entry);
   421   my $source = get_source_from_entry($entry);
   399   my $target = get_target_from_entry($entry);
   422   my $target = get_target_from_entry($entry);
   400   #convert the \\01\\ to \\%02d\\
   423   #convert the \\01\\ to \\%02d\\
   401   $source =~ s/\\01\\/\\%02d\\/i;
   424   $source =~ s/([\/\\])01([\/\\])/$1%02d$2/i;
   402   $target =~ s/\\01\\/\\%02d\\/i;
   425   $target =~ s/([\/\\])01([\/\\])/$1%02d$2/i;
   403   #print "create_localise_entry_from_resource: $source\n";
   426   #print "create_localise_entry_from_resource: $source\n";
   404   return "$type=LOCALISE($source, $target)";
   427   return "$type=LOCALISE($source, $target)";
   405 }
   428 }
   406 
   429 
   407 # create localise entry from help entry hlp
   430 # create localise entry from help entry hlp
   466 # create localisable path from /00/ or /01/ paths
   489 # create localisable path from /00/ or /01/ paths
   467 sub create_localisable_path($)
   490 sub create_localisable_path($)
   468 {
   491 {
   469   my $entry = shift;
   492   my $entry = shift;
   470 
   493 
   471   $entry =~ s/\\01\\/\\%02d\\/ig;
   494   $entry =~ s/([\/\\])01([\/\\])/$1%02d$2/ig;
   472   $entry =~ s/\\00\\/\\%02d\\/ig;
   495   $entry =~ s/([\/\\])00([\/\\])/$1%02d$2/ig;
   473 
   496 
   474   #print "create_localise_entry_from_resource: $source\n";
   497   #print "create_localise_entry_from_resource: $source\n";
   475   return $entry;
   498   return $entry;
   476 }
   499 }
   477 1;  # Return a true value from the file
   500 1;  # Return a true value from the file