diff --git a/console/tidy.c b/console/tidy.c index dba7e64..92121bc 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -2022,7 +2022,7 @@ static Bool TIDY_CALL reportCallback(TidyMessage tmessage) TidyFormatParameterType messageType; ctmbstr messageFormat; - printf("FILTER: %s, %s\n", tidyGetMessageKey( tmessage ), tidyGetMessageOutput( tmessage )); + printf("FILTER: %s\n%s\n%s\n", tidyGetMessageKey( tmessage ), tidyGetMessageOutput( tmessage ), tidyGetMessageOutputDefault( tmessage )); /* loop through the arguments, if any, and print their details */ pos = tidyGetMessageArguments( tmessage ); diff --git a/include/tidy.h b/include/tidy.h index 45264d9..0235636 100644 --- a/include/tidy.h +++ b/include/tidy.h @@ -2125,6 +2125,16 @@ TIDY_EXPORT ctmbstr TIDY_CALL tidyLocalizedStringN(uint messageType, /**< The me */ TIDY_EXPORT ctmbstr TIDY_CALL tidyLocalizedString( uint messageType ); +/** Provides a string given `messageType` in the default localization for + ** `quantity`. Some strings have one or more plural forms, and this function + ** will ensure that the correct singular or plural form is returned for the + ** specified quantity. + ** @result Returns the desired string. + */ +TIDY_EXPORT ctmbstr TIDY_CALL tidyDefaultStringN(uint messageType, /**< The message type. */ + uint quantity /**< The quantity. */ + ); + /** Provides a string given `messageType` in the default localization (which ** is `en`). ** @param messageType The message type. diff --git a/src/language.c b/src/language.c index d52d015..aa61ca5 100644 --- a/src/language.c +++ b/src/language.c @@ -476,6 +476,16 @@ TY_PRIVATE void TY_(tidySetLanguageSetByUser)( void ) } +/** + * Provides a string given `messageType` in the default + * localization (which is `en`), for the given quantity. + */ +TY_PRIVATE ctmbstr TY_(tidyDefaultStringN)( uint messageType, uint quantity ) +{ + return tidyLocalizedStringImpl( messageType, &language_en, quantity); +} + + /** * Provides a string given `messageType` in the default * localization (which is `en`), for single plural form. diff --git a/src/language.h b/src/language.h index 05f2829..a02756b 100644 --- a/src/language.h +++ b/src/language.h @@ -153,6 +153,12 @@ TY_PRIVATE ctmbstr TY_(tidyLocalizedString)( uint messageType ); /** @{ */ +/** + * Provides a string given `messageType` in the default + * localization (which is `en`), for the given quantity. + */ +TY_PRIVATE ctmbstr TY_(tidyDefaultStringN)( uint messageType, uint quantity ); + /** * Provides a string given `messageType` in the default * localization (which is `en`). diff --git a/src/message.c b/src/message.c index dfb9fa2..90f74e0 100644 --- a/src/message.c +++ b/src/message.c @@ -50,9 +50,9 @@ static char* TagToString(Node* tag, char* buf, size_t count) else if (tag->type == DocTypeTag) TY_(tmbsnprintf)(buf, count, ""); else if (tag->type == TextNode) - TY_(tmbsnprintf)(buf, count, "%s", tidyLocalizedString(STRING_PLAIN_TEXT)); + TY_(tmbsnprintf)(buf, count, "%s", "STRING_PLAIN_TEXT"); else if (tag->type == XmlDecl) - TY_(tmbsnprintf)(buf, count, "%s", tidyLocalizedString(STRING_XML_DECLARATION)); + TY_(tmbsnprintf)(buf, count, "%s", "STRING_XML_DECLARATION"); else if (tag->element) TY_(tmbsnprintf)(buf, count, "%s", tag->element); } @@ -1070,7 +1070,7 @@ static struct _dialogueDispatchTable { /* This message formatter for dialogue messages should be capable of formatting -** every message, because they're not all the complex and there aren't that +** every message, because they're not all that complex and there aren't that ** many. */ static TidyMessageImpl *formatDialogue( TidyDocImpl* doc, uint code, TidyReportLevel level, va_list args ) @@ -1087,8 +1087,8 @@ static TidyMessageImpl *formatDialogue( TidyDocImpl* doc, uint code, TidyReportL case STRING_ERROR_COUNT: case STRING_NOT_ALL_SHOWN: return TY_(tidyMessageCreate)( doc, code, level, - doc->warnings, tidyLocalizedStringN( STRING_ERROR_COUNT_WARNING, doc->warnings ), - doc->errors, tidyLocalizedStringN( STRING_ERROR_COUNT_ERROR, doc->errors ) ); + doc->warnings, "STRING_ERROR_COUNT_WARNING", + doc->errors, "STRING_ERROR_COUNT_ERROR" ); case FOOTNOTE_TRIM_EMPTY_ELEMENT: case STRING_HELLO_ACCESS: diff --git a/src/messageobj.c b/src/messageobj.c index 93d5504..1b986b7 100644 --- a/src/messageobj.c +++ b/src/messageobj.c @@ -40,7 +40,6 @@ struct printfArg { }; - /** Returns a pointer to an allocated array of `printfArg` given a format ** string and a va_list, or NULL if not successful or no parameters were ** given. Parameter `rv` will return with the count of zero or more @@ -130,6 +129,22 @@ static TidyMessageImpl *tidyMessageCreateInitV( TidyDocImpl *doc, TY_(tmbvsnprintf)(result->message, sizeMessageBuf, result->messageFormat, args_copy); va_end(args_copy); + /* Some things already hit us localized, and some things need to be + localized here. Look for these codewords and replace them here. + */ + TY_(strrep)(result->messageDefault, "STRING_PLAIN_TEXT", tidyDefaultString(STRING_PLAIN_TEXT)); + TY_(strrep)(result->message, "STRING_PLAIN_TEXT", tidyLocalizedString(STRING_PLAIN_TEXT)); + + TY_(strrep)(result->messageDefault, "STRING_XML_DECLARATION", tidyDefaultString(STRING_XML_DECLARATION)); + TY_(strrep)(result->message, "STRING_XML_DECLARATION", tidyLocalizedString(STRING_XML_DECLARATION)); + + TY_(strrep)(result->messageDefault, "STRING_ERROR_COUNT_WARNING", tidyDefaultStringN(STRING_ERROR_COUNT_WARNING, doc->warnings)); + TY_(strrep)(result->message, "STRING_ERROR_COUNT_WARNING", tidyLocalizedStringN(STRING_ERROR_COUNT_WARNING, doc->warnings)); + + TY_(strrep)(result->messageDefault, "STRING_ERROR_COUNT_ERROR", tidyDefaultStringN(STRING_ERROR_COUNT_ERROR, doc->errors)); + TY_(strrep)(result->message, "STRING_ERROR_COUNT_ERROR", tidyLocalizedStringN(STRING_ERROR_COUNT_ERROR, doc->errors)); + + result->messagePosDefault = TidyDocAlloc(doc, sizeMessageBuf); result->messagePos = TidyDocAlloc(doc, sizeMessageBuf); diff --git a/src/tidylib.c b/src/tidylib.c index a439629..f401323 100644 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -2643,6 +2643,11 @@ ctmbstr TIDY_CALL tidyLocalizedString( uint messageType ) return TY_(tidyLocalizedString)( messageType ); } +ctmbstr TIDY_CALL tidyDefaultStringN( uint messageType, uint quantity ) +{ + return TY_(tidyDefaultStringN)( messageType, quantity); +} + ctmbstr TIDY_CALL tidyDefaultString( uint messageType ) { return TY_(tidyDefaultString)( messageType ); diff --git a/src/tmbstr.c b/src/tmbstr.c index 0cfe5f2..e352698 100644 --- a/src/tmbstr.c +++ b/src/tmbstr.c @@ -247,6 +247,36 @@ int TY_(tmbsnprintf)(tmbstr buffer, size_t count, ctmbstr format, ...) return retval; } +void TY_(strrep)(tmbstr buffer, ctmbstr str, ctmbstr rep) +{ + char *p = strstr(buffer, str); + do + { + if(p) + { + char buf[1024]; + memset(buf,'\0',strlen(buf)); + + if(buffer == p) + { + strcpy(buf,rep); + strcat(buf,p+strlen(str)); + } + else + { + strncpy(buf,buffer,strlen(buffer) - strlen(p)); + strcat(buf,rep); + strcat(buf,p+strlen(str)); + } + + memset(buffer,'\0',strlen(buffer)); + strcpy(buffer,buf); + } + + } while(p && (p = strstr(buffer, str))); +} + + /* * local variables: * mode: c diff --git a/src/tmbstr.h b/src/tmbstr.h index 46a50e1..b384b76 100644 --- a/src/tmbstr.h +++ b/src/tmbstr.h @@ -79,6 +79,9 @@ __attribute__((format(printf, 3, 4))) #endif ; +TY_PRIVATE void TY_(strrep)(tmbstr buffer, ctmbstr str, ctmbstr rep); + + #ifdef __cplusplus } /* extern "C" */ #endif