[CHKDSK] Implement localization support (#891)
authorBișoc George <fraizeraust99@gmail.com>
Sat, 20 Oct 2018 19:21:51 +0000 (21:21 +0200)
committerHermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Sat, 20 Oct 2018 19:21:51 +0000 (21:21 +0200)
- Make the strings translatable.
- Include the English translation within the main resource file.
- Use ConResPrintf() and ConResPuts() for resource strings.

base/system/chkdsk/chkdsk.c
base/system/chkdsk/chkdsk.rc
base/system/chkdsk/lang/en-US.rc [new file with mode: 0644]
base/system/chkdsk/resource.h [new file with mode: 0644]

index 76dc975..6fc25f7 100644 (file)
@@ -49,6 +49,9 @@
 
 #include <conutils.h>
 
 
 #include <conutils.h>
 
+/* Resource header */
+#include "resource.h"
+
 #define NTOS_MODE_USER
 #include <ndk/ntndk.h>
 
 #define NTOS_MODE_USER
 #include <ndk/ntndk.h>
 
@@ -85,9 +88,9 @@ PCHKDSK Chkdsk;
 // Takes the win32 error code and prints the text version.
 //
 //----------------------------------------------------------------------
 // Takes the win32 error code and prints the text version.
 //
 //----------------------------------------------------------------------
-static VOID PrintWin32Error(LPWSTR Message, DWORD ErrorCode)
+static VOID PrintWin32Error(int Message, DWORD ErrorCode)
 {
 {
-    ConPrintf(StdErr, L"%s: ", Message);
+    ConResPuts(StdErr, Message);
     ConMsgPuts(StdErr, FORMAT_MESSAGE_FROM_SYSTEM,
                NULL, ErrorCode, LANG_USER_DEFAULT);
     ConPuts(StdErr, L"\n");
     ConMsgPuts(StdErr, FORMAT_MESSAGE_FROM_SYSTEM,
                NULL, ErrorCode, LANG_USER_DEFAULT);
     ConPuts(StdErr, L"\n");
@@ -123,14 +126,7 @@ CtrlCIntercept(DWORD dwCtrlType)
 static VOID
 Usage(PWCHAR ProgramName)
 {
 static VOID
 Usage(PWCHAR ProgramName)
 {
-    ConPrintf(StdOut,
-        L"Usage: %s [drive:] [-F] [-V] [-R] [-C]\n\n"
-        L"[drive:]    Specifies the drive to check.\n"
-        L"-F          Fixes errors on the disk.\n"
-        L"-V          Displays the full path of every file on the disk.\n"
-        L"-R          Locates bad sectors and recovers readable information.\n"
-        L"-C          Checks the drive only if it is dirty.\n\n",
-        ProgramName);
+    ConResPrintf(StdOut, IDS_USAGE, ProgramName);
 }
 
 
 }
 
 
@@ -261,7 +257,7 @@ ChkdskCallback(
             break;
 
         case VOLUMEINUSE:
             break;
 
         case VOLUMEINUSE:
-            ConPuts(StdOut, L"Volume is in use and cannot be locked\n");
+            ConResPuts(StdOut, IDS_VOLUME_IN_USE);
             Ret = FALSE;
             break;
 
             Ret = FALSE;
             break;
 
@@ -299,7 +295,7 @@ ChkdskCallback(
 
         case PROGRESS:
             percent = (PDWORD)Argument;
 
         case PROGRESS:
             percent = (PDWORD)Argument;
-            ConPrintf(StdOut, L"%d percent completed.\r", *percent);
+            ConResPrintf(StdOut, IDS_PERCENT_COMPL, *percent);
             break;
 
         case OUTPUT:
             break;
 
         case OUTPUT:
@@ -311,7 +307,7 @@ ChkdskCallback(
             status = (PBOOLEAN)Argument;
             if (*status == FALSE)
             {
             status = (PBOOLEAN)Argument;
             if (*status == FALSE)
             {
-                ConPuts(StdOut, L"Chkdsk was unable to complete successfully.\n\n");
+                ConResPuts(StdOut, IDS_CHKDSK_FAIL);
                 Error = TRUE;
             }
             break;
                 Error = TRUE;
             }
             break;
@@ -371,11 +367,7 @@ wmain(int argc, WCHAR *argv[])
     /* Initialize the Console Standard Streams */
     ConInitStdStreams();
 
     /* Initialize the Console Standard Streams */
     ConInitStdStreams();
 
-    ConPuts(StdOut,
-        L"\n"
-        L"Chkdskx v1.0.1 by Mark Russinovich\n"
-        L"Systems Internals - http://www.sysinternals.com\n"
-        L"ReactOS adaptation 1999 by Emanuele Aliberti\n\n");
+    ConResPuts(StdOut, IDS_ABOUT);
 
 #ifndef FMIFS_IMPORT_DLL
     //
 
 #ifndef FMIFS_IMPORT_DLL
     //
@@ -383,7 +375,7 @@ wmain(int argc, WCHAR *argv[])
     //
     if (!LoadFMIFSEntryPoints())
     {
     //
     if (!LoadFMIFSEntryPoints())
     {
-        ConPuts(StdErr, L"Could not located FMIFS entry points.\n\n");
+        ConResPuts(StdErr, IDS_NO_ENTRY_POINT);
         return -1;
     }
 #endif
         return -1;
     }
 #endif
@@ -394,7 +386,7 @@ wmain(int argc, WCHAR *argv[])
     badArg = ParseCommandLine(argc, argv);
     if (badArg)
     {
     badArg = ParseCommandLine(argc, argv);
     if (badArg)
     {
-        ConPrintf(StdOut, L"Unknown argument: %s\n", argv[badArg]);
+        ConResPrintf(StdOut, IDS_BAD_ARGUMENT, argv[badArg]);
         Usage(argv[0]);
         return -1;
     }
         Usage(argv[0]);
         return -1;
     }
@@ -406,7 +398,7 @@ wmain(int argc, WCHAR *argv[])
     {
         if (!GetCurrentDirectoryW(ARRAYSIZE(CurrentDirectory), CurrentDirectory))
         {
     {
         if (!GetCurrentDirectoryW(ARRAYSIZE(CurrentDirectory), CurrentDirectory))
         {
-            PrintWin32Error(L"Could not get current directory", GetLastError());
+            PrintWin32Error(IDS_NO_CURRENT_DIR, GetLastError());
             return -1;
         }
     }
             return -1;
         }
     }
@@ -431,7 +423,7 @@ wmain(int argc, WCHAR *argv[])
                                fileSystem,
                                ARRAYSIZE(fileSystem)))
     {
                                fileSystem,
                                ARRAYSIZE(fileSystem)))
     {
-        PrintWin32Error(L"Could not query volume", GetLastError());
+        PrintWin32Error(IDS_NO_QUERY_VOL, GetLastError());
         return -1;
     }
 
         return -1;
     }
 
@@ -450,7 +442,7 @@ wmain(int argc, WCHAR *argv[])
                                    0);
         if (volumeHandle == INVALID_HANDLE_VALUE)
         {
                                    0);
         if (volumeHandle == INVALID_HANDLE_VALUE)
         {
-            ConPuts(StdErr, L"Chkdsk cannot run because the volume is in use by another process.\n\n");
+            ConResPuts(StdErr, IDS_VOLUME_IN_USE_PROC);
             return -1;
         }
         CloseHandle(volumeHandle);
             return -1;
         }
         CloseHandle(volumeHandle);
@@ -464,7 +456,7 @@ wmain(int argc, WCHAR *argv[])
     //
     // Just do it
     //
     //
     // Just do it
     //
-    ConPrintf(StdOut, L"The type of file system is %s.\n", fileSystem);
+    ConResPrintf(StdOut, IDS_FILE_SYSTEM, fileSystem);
     Chkdsk(Drive,
            fileSystem,
            FixErrors,
     Chkdsk(Drive,
            fileSystem,
            FixErrors,
index 17962ee..412971c 100644 (file)
@@ -1,6 +1,15 @@
+#include <windef.h>
+#include "resource.h"
 
 #define REACTOS_STR_FILE_DESCRIPTION    "ReactOS Disk Checking Utility"
 #define REACTOS_STR_INTERNAL_NAME       "chkdsk"
 #define REACTOS_STR_ORIGINAL_FILENAME   "chkdsk.exe"
 #define REACTOS_STR_ORIGINAL_COPYRIGHT  "1998 Mark Russinovich"
 #include <reactos/version.rc>
 
 #define REACTOS_STR_FILE_DESCRIPTION    "ReactOS Disk Checking Utility"
 #define REACTOS_STR_INTERNAL_NAME       "chkdsk"
 #define REACTOS_STR_ORIGINAL_FILENAME   "chkdsk.exe"
 #define REACTOS_STR_ORIGINAL_COPYRIGHT  "1998 Mark Russinovich"
 #include <reactos/version.rc>
+
+/* UTF-8 */
+#pragma code_page(65001)
+
+#ifdef LANGUAGE_EN_US
+    #include "lang/en-US.rc"
+#endif
diff --git a/base/system/chkdsk/lang/en-US.rc b/base/system/chkdsk/lang/en-US.rc
new file mode 100644 (file)
index 0000000..c36ed8d
--- /dev/null
@@ -0,0 +1,31 @@
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+
+STRINGTABLE
+BEGIN
+    IDS_USAGE "\n\
+Usage: %s [drive:] [-F] [-V] [-R] [-C] \n\n\
+[drive:]    Specifies the drive to check.\n\
+-F          Fixes errors on the disk.\n\
+-V          Displays the full path of every file on the disk.\n\
+-R          Locates bad sectors and recovers readable information.\n\
+-C          Checks the drive only if it is dirty.\n\
+\n"
+
+    IDS_PERCENT_COMPL "%d percent completed.\r"
+    IDS_FILE_SYSTEM "The type of file system is %s.\n"
+    IDS_ABOUT "\n\
+Chkdskx v1.0.1 by Mark Russinovich\n\
+Systems Internals - http://www.sysinternals.com\n\
+ReactOS adaptation 1999 by Emanuele Aliberti\n\n"
+END
+
+STRINGTABLE
+BEGIN
+    IDS_VOLUME_IN_USE "Volume is in use and cannot be locked\n"
+    IDS_CHKDSK_FAIL "Chkdsk was unable to complete successfully.\n\n"
+    IDS_NO_ENTRY_POINT "Could not located FMIFS entry points.\n\n"
+    IDS_BAD_ARGUMENT "Unknown argument: %s\n"
+    IDS_NO_CURRENT_DIR "Could not get current directory. Error code: "
+    IDS_NO_QUERY_VOL "Could not query volume. Error code: "
+    IDS_VOLUME_IN_USE_PROC "Chkdsk cannot run because the volume is in use by another process.\n\n"
+END
diff --git a/base/system/chkdsk/resource.h b/base/system/chkdsk/resource.h
new file mode 100644 (file)
index 0000000..a5597dd
--- /dev/null
@@ -0,0 +1,18 @@
+/* General IDs */
+
+#define IDS_USAGE               101
+#define IDS_PERCENT_COMPL       102
+#define IDS_ABOUT               103
+#define IDS_FILE_SYSTEM         104
+
+/* Failure IDs */
+
+#define IDS_VOLUME_IN_USE       200
+#define IDS_CHKDSK_FAIL         201
+#define IDS_NO_ENTRY_POINT      202
+#define IDS_BAD_ARGUMENT        203
+#define IDS_NO_CURRENT_DIR      204
+#define IDS_NO_QUERY_VOL        205
+#define IDS_VOLUME_IN_USE_PROC  206
+
+/* EOF */