int main(int argc, char* argv[]) { // Basic syntax checking for "-x name" format while ((argc > 2) && (argv[1][0] == '-') && (argv[1][1] != '\x00') && (argv[1][2] == '\x00') && (argv[2][0] != '\x00') && (argv[2][0] != '-')) { switch (argv[1][1]) { case 's': --argc; ++argv; pSourceDirectory = argv[1]; break; } ++argv; --argc; } if (pSourceDirectory == NULL) { printf("\nWrong Arguments given !\n"); PrintUsage(); return 1; } printf("\nXBMC-XML2PO v0.96 by Team XBMC\n"); ProjRootDir = pSourceDirectory; ProjRootDir = AddSlash(ProjRootDir); if ((FileExist(ProjRootDir + "addon.xml")) && (FileExist(ProjRootDir + "resources" + DirSepChar + "language" + DirSepChar + "English" + DirSepChar + "strings.xml"))) projType = ADDON; else if ((FileExist(ProjRootDir + "addon.xml")) && (FileExist(ProjRootDir + "language" + DirSepChar + "English" + DirSepChar + "strings.xml"))) projType = SKIN; else if (FileExist(ProjRootDir + "addon.xml")) projType = ADDON_NOSTRINGS; else if (FileExist(ProjRootDir + "xbmc" + DirSepChar + "GUIInfoManager.h")) projType = CORE; else projType = UNKNOWN; std::string strprojType; switch (projType) { case ADDON: strprojType = "Addon with translatable strings"; WorkingDir = ProjRootDir + DirSepChar + "resources" + DirSepChar + "language"+ DirSepChar; break; case SKIN: strprojType = "Skin addon"; WorkingDir = ProjRootDir + DirSepChar + "language"+ DirSepChar; break; case ADDON_NOSTRINGS: strprojType = "Addon without any translatable strings"; break; case CORE: strprojType = "XBMC core"; WorkingDir = ProjRootDir + DirSepChar + "language" + DirSepChar; break; default: strprojType = "Unknown"; WorkingDir = ProjRootDir; break; } if (projType == ADDON || projType == ADDON_NOSTRINGS || projType == SKIN) loadAddonXMLFile(ProjRootDir + "addon.xml"); else if (projType == CORE) { ProjTextName = "XBMC Core"; ProjProvider = "Team XBMC"; ProjName = "xbmc.core"; LoadCoreVersion(ProjRootDir + "xbmc" + DirSepChar + "GUIInfoManager.h"); } printf ("Project type detected:\t%s\n", strprojType.c_str()); printf ("\nProject name:\t\t%s\n", ProjTextName.c_str()); printf ("Project id:\t\t%s\n", ProjName.c_str()); printf ("Project version:\t%s\n", ProjVersion.c_str()); printf ("Project provider:\t%s\n", ProjProvider.c_str()); if (projType == ADDON_NOSTRINGS) { if (!DirExists(ProjRootDir + "resources") && (!MakeDir(ProjRootDir + "resources"))) { printf ("fatal error: not able to create resources directory at dir: %s", ProjRootDir.c_str()); return 1; } if (!DirExists(ProjRootDir + "resources" + DirSepChar + "language") && (!MakeDir(ProjRootDir + "resources"+ DirSepChar + "language"))) { printf ("fatal error: not able to create language directory at dir: %s", (ProjRootDir + "resources").c_str()); return 1; } WorkingDir = ProjRootDir + "resources"+ DirSepChar + "language" + DirSepChar; for (itAddonXMLData = mapAddonXMLData.begin(); itAddonXMLData != mapAddonXMLData.end(); itAddonXMLData++) { if (!DirExists(WorkingDir + FindLang(itAddonXMLData->first)) && (!MakeDir(WorkingDir + FindLang(itAddonXMLData->first)))) { printf ("fatal error: not able to create %s language directory at dir: %s", itAddonXMLData->first.c_str(), WorkingDir.c_str()); return 1; } } } if (projType !=ADDON_NOSTRINGS && !loadXMLFile(xmlDocSourceInput, WorkingDir + "English" + DirSepChar + "strings.xml", &mapSourceXmlId, true)) { printf("Fatal error: no English source xml file found or it is corrupted\n"); return 1; } printf("\nResults:\n\n"); printf("Langcode\tString match\tOutput file\n"); printf("--------------------------------------------------------------\n"); ConvertXML2PO(WorkingDir + "English" + DirSepChar, "en", 2, "(n != 1)", false); DIR* Dir; struct dirent *DirEntry; Dir = opendir(WorkingDir.c_str()); int langcounter =0; std::map<std::string, CLangData> mapLangList; std::map<std::string, CLangData>::iterator itmapLangList; while((DirEntry=readdir(Dir))) { if (DirEntry->d_type == DT_DIR && DirEntry->d_name[0] != '.' && strcmp(DirEntry->d_name, "English")) { CLangData Langdat; Langdat.LLangCode = FindLangCode(DirEntry->d_name); Langdat.LPlurals = GetnPlurals(DirEntry->d_name); Langdat.LPlurForm = GetPlurForm(DirEntry->d_name); mapLangList [DirEntry->d_name] = Langdat; } } for (itmapLangList = mapLangList.begin(); itmapLangList != mapLangList.end(); itmapLangList++) { bool bRunConvert = false;; if (projType == ADDON_NOSTRINGS || projType == ADDON || projType == SKIN) bRunConvert = true; if ((projType != ADDON_NOSTRINGS && loadXMLFile(xmlDocForeignInput, WorkingDir + itmapLangList->first + DirSepChar + "strings.xml", &mapForeignXmlId, false)) || bRunConvert) { ConvertXML2PO(WorkingDir + itmapLangList->first + DirSepChar, itmapLangList->second.LLangCode, itmapLangList->second.LPlurals, itmapLangList->second.LPlurForm, true); langcounter++; } } printf("\nReady. Processed %i languages.\n", langcounter+1); if (bUnknownLangFound) printf("\nWarning: At least one language found with unpaired language code !\n" "Please edit the .po file manually and correct the language code, plurals !\n" "Also please report this to [email protected] if possible !\n\n"); return 0; }
int main(int argc, char* argv[]) { bBreakLines = false; // By default we don't break lines // Basic syntax checking for "-x name" format while ((argc > 2) && (argv[1][0] == '-') && (argv[1][1] != '\x00') && (argv[1][2] == '\x00') && (argv[2][0] != '\x00') && (argv[2][0] != '-')) { switch (argv[1][1]) { case 's': --argc; ++argv; pSourceDirectory = argv[1]; break; case 'p': --argc; ++argv; pProjectName = argv[1]; break; case 'v': --argc; ++argv; pVersionNumber = argv[1]; break; case 'b': --argc; ++argv; pBreaklineOption = argv[1]; break; } ++argv; --argc; } if (pSourceDirectory == NULL) { printf("\nWrong Arguments given !\n"); PrintUsage(); return 1; } if (pBreaklineOption != NULL) bBreakLines = true; printf("\nXBMC-XML2PO v0.9 by Team XBMC\n"); printf("\nResults:\n\n"); printf("Langcode\tString match\tAuto contexts\tOutput file\n"); printf("--------------------------------------------------------------\n"); WorkingDir = pSourceDirectory; if (WorkingDir[0] != DirSepChar[0]) WorkingDir.append(DirSepChar); if (!loadXMLFile(xmlDocSourceInput, WorkingDir + "English" + DirSepChar + "strings.xml", &mapSourceXmlId, true)) { printf("Fatal error: no English source xml file found or it is corrupted\n"); return 1; } ConvertXML2PO(WorkingDir + "English" + DirSepChar, "en", 2, "(n != 1)", false); DIR* Dir; struct dirent *DirEntry; Dir = opendir(WorkingDir.c_str()); int langcounter =0; while((DirEntry=readdir(Dir))) { std::string LName = ""; if (DirEntry->d_type == DT_DIR && DirEntry->d_name[0] != '.' && strcmp(DirEntry->d_name, "English")) { if (loadXMLFile(xmlDocForeignInput, WorkingDir + DirEntry->d_name + DirSepChar + "strings.xml", &mapForeignXmlId, false)) { ConvertXML2PO(WorkingDir + DirEntry->d_name + DirSepChar, FindLangCode(DirEntry->d_name), GetnPlurals(DirEntry->d_name), GetPlurForm(DirEntry->d_name), true); langcounter++; } } } printf("\nReady. Processed %i languages.\n", langcounter+1); if (bUnknownLangFound) printf("\nWarning: At least one language found with unpaired language code !\n" "Please edit the .po file manually and correct the language code, plurals !\n" "Also please report this to [email protected] if possible !\n\n"); return 0; }