YAFLogo

shide
  • shide
  • 80.6% (Honored)
  • YAF Lover Topic Starter
10 years ago
Hi everyone,

i just wanted to warn you when you translate your files, beware of those special characters like < ' >.

They might slip into some jquery and blow everything up 🙂 error: unexpected identifier

(This might be why 'we' french people are always complaining about problems ^^)

We have some texte like "aucune donnée n'a été trouvée" and the <'> was causing an issue.

In "YAF.Controls.UserLink" around line 158, it used to be :


           // Setup Hover Card JS
            YafContext.Current.PageElements.RegisterJsBlockStartup(
                "yafhovercardtjs",
                "if (typeof(jQuery.fn.hovercard) != 'undefined'){{ {0}('.userHoverCard').hovercard({{showYafCard: true, delay: {1}, width: 350,loadingHTML: '{2}',errorHTML: '{3}'}}); }}"
                    .FormatWith(
                        Config.JQueryAlias,
                        this.Get<YafBoardSettings>().HoverCardOpenDelay,
                        this.GetText("DEFAULT", "LOADING_HOVERCARD"),
                        this.GetText("DEFAULT", "ERROR_HOVERCARD")));
So i've added the extension method "ToJsString()", to make sure that those special char don't slip in the Jquery :


           // Setup Hover Card JS
            YafContext.Current.PageElements.RegisterJsBlockStartup(
                "yafhovercardtjs",
                "if (typeof(jQuery.fn.hovercard) != 'undefined'){{ {0}('.userHoverCard').hovercard({{showYafCard: true, delay: {1}, width: 350,loadingHTML: '{2}',errorHTML: '{3}'}}); }}"
                    .FormatWith(
                        Config.JQueryAlias,
                        this.Get<YafBoardSettings>().HoverCardOpenDelay,
                        this.GetText("DEFAULT", "LOADING_HOVERCARD").ToJsString(),
                        this.GetText("DEFAULT", "ERROR_HOVERCARD").ToJsString()));

I think that it's not the only place where that kind of verification should be added, since there are more places where translated text is formatted in jquery ?

if i look for every reference to the "YafContext.Current.PageElements.RegisterJsBlockStartup()" method, there are about 47 other calls.

Those should probably receive the same treatment :)

Hope this help !

Sponsor
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
10 years ago
Thx i implemented the fix.

PS: You do know that you can send in pull request, for such code fixes?

shide
  • shide
  • 80.6% (Honored)
  • YAF Lover Topic Starter
10 years ago
Yep but i didn't figure out how to do that. i'll check that when i'll have time 🙂