hedgewars/uSound.pas
changeset 5107 d7fc678d78f4
parent 5052 74a81c276d67
child 5134 97827ad5c904
--- a/hedgewars/uSound.pas	Tue Apr 05 20:28:44 2011 +0200
+++ b/hedgewars/uSound.pas	Tue Apr 05 16:23:52 2011 -0400
@@ -20,7 +20,7 @@
 
 unit uSound;
 interface
-uses SDLh, uConsts, uTypes;
+uses SDLh, uConsts, uTypes, sysutils;
 
 var MusicFN: shortstring;
 
@@ -61,13 +61,29 @@
 
 function  AskForVoicepack(name: shortstring): Pointer;
 var i: Longword;
+    locName, path: shortstring;
 begin
 i:= 0;
+    // First, attempt to locate a localised version of the voice
+    if cLocale <> 'en' then
+        begin
+        locName:= name+'_'+cLocale;
+        path:= Pathz[ptVoices] + '/' + locName;
+        if DirectoryExists(path) then name:= locName
+        else if Length(cLocale) > 2 then
+            begin
+            locName:= name+'_'+Copy(cLocale,1,2);
+            path:= Pathz[ptVoices] + '/' + locName;
+            if DirectoryExists(path) then name:= locName
+            end
+        end;
+
+    // If that fails, use the unmodified one
     while (voicepacks[i].name <> name) and (voicepacks[i].name <> '') do
-    begin
+        begin
         inc(i);
         TryDo(i <= cMaxTeams, 'Engine bug: AskForVoicepack i > cMaxTeams', true)
-    end;
+        end;
 
     voicepacks[i].name:= name;
     AskForVoicepack:= @voicepacks[i]