Developer forum

Forum » CMS - Standard features » Some times GetTranslation doesn't return the translate value (anymore)

Some times GetTranslation doesn't return the translate value (anymore)

Peter Leleulya
Peter Leleulya
Reply

Hi guys,

In almost every project we have a helper class which we use to retrieve a translation from the translation.xml when we are in code in stead of a template.
This has never given us any problems until the beginning of februari for just 1 project.
And we cannot figure out what the F is going on and why it SOMETIMES doesn't work ...

This helper function hasn't been changed, the dynamicweb dlls haven't changed and the xml file is valid.

It results in very ugly translate keys being shown on the website and in e-mails, so we really need to get this fixed.
Hopefully anyone can point us in the right direction after reading the following:

Our helper function retrieves the design and calls Dynamicweb.Rendering.Translation.Translation.GetTranslation(keyword, cultureInfo, design)
This GetTranslation returns the translation value for the entered keyword based on culturinfo from the xml file based on the design.
It has a fallback to return the keyword if no translation was found.

This dynamicweb function seems to be using a cached value as source, which makes a lot of sense.

Somehow we started getting keywords as output value, while those keywords did exist in the translation.xml and this xml file was valid.
After a while the problem went away, but it returns ones in a while.

We added extra logging in our helper function, which logs whenever the input value is equal to the output value.
At that moment we also log Dynamicweb.Rendering.Translation.Translation.GetTranslationKeys(KeyScope.DesignsLocal, design).Count, which indicates the number of translations available in the cached data.
There are many log lines that were expected, since a key vale can be the translation for one of the languages. In those cases the key count was 2085.
But then we also see log lines with obvious key names like DefaultMailTitle, which should be translate, but weren't! In those cases the key count was 0! (or a low number)

I guess in those cases the translate function was trying to get a translation from an empty cache file or something, which obviously doesn't work, so it returned the keyword.
And this gets automagically fixed at a point when the cache gets refilled by the origional xml document.

What we can't figure out is WHY the translation keys got flushed.

Is it something from the hosting environment?
I've tried to match appool recycles and eventviewer errors with the log times, but couldn't find a clear match.

Is there some additional logging available from DW functions to find out why this happens?
Is there a workaround?

Is there a better way to retrieve translations from c# code?

I can't really make a workaround on our side, since we can't know in which cases the return value should be equal to the input value and when it shouldn't.

I hope anyone can help me in this matter.


Replies

 
Nicolai Pedersen
Reply

I cannot see why this should happen - unless those keys are not in the design local translation file...

You could, when you detect that the return value is the same AND that the count of keys are 0, reset the translation source cache like this:

Dynamicweb.Caching.Cache.Current.Remove($"Translation.Source.{design.name}");

And then call the GetTranslation again...

 
Martin Vang
Martin Vang
Reply

I have a couple of things that you can take a look at:

1. Does the machine have a low amount of free memory when it happens?

2. When was the ["Translation.Source." + designName]-file last touched in relation to the problem?

The reason I ask is, that our translations (source) is stored in a memory-cache, and that cache will try to aggresively purge data when memory is running out OR when the dependency (here the file in question) is being touced/updated. And we have this piece of code:

            if (src == null)
            {
                return @default;
            }

where @default is the key (often a "strange value"), and src is the Source from cache. Since we simply use Microsofts implementation of a memorycache underneath, Id have to dig a lot to find out when / how it purges data to be sure, but it sounds as if "src" is somehow null based upon your logging.

Hope you find a culpit to the problem - or at least find a way to guard against it!

BR

Martin

 

You must be logged in to post in the forum