Is it possible to use a .resx file for custom resource keys?

Tom Troughton asked on May 26, 2016 12:53

Hi everyone,

From Kentico's documentation I can see it's possible to override UI resource keys in a custom.resx file. I'm wondering if it's possible to follow a similar approach to create my own resource keys?

The reason is, working in a team development environment we're having difficulties because resource strings are not serialized so are not being shared between developers when using the Continuous Integration module. It'd be great if we could avoid the Localization module and use resx files instead for our own resource keys.

We still need to be able to use these resource keys in macros, for example when naming web part properties.

Any advice appreciated.

Update following Jan's answer:

As Jan says, you can put custom resource strings into custom.resx. I think the reason it wasn't working for me was because when you add a resx in Visual Studio it adds as an embedded resource with an accompanying designer.cs file. Once I'd deleted this code file and changed my resx file's properties to "Content" build action and "Do not copy" for 'copy to output directory' everything started working. Hopefully will help someone in future.

Correct Answer

Jan Šedo answered on May 26, 2016 14:54

Hello Nat, yes you can add your own custom resource keys to the custom.resx file. The documentation only states that if you want to override resource strings, they have to have same identical key. When you add a new key, don't forget to clear the application's cache and restart it so the changes take place.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on May 26, 2016 15:30

I'm confused as to why you'd want to use a custom .resx file when you can use the Localization module. I understand the objects aren't serialized but why do you need them to be? The keys are content, use the staging module to move them from one environment to the next, CI shouldn't be needed for that.

Straight from the documentation:

When loading resource strings, the system uses the following priority:

  1. database (Localization application) – highest priority
  2. site specific resx files
  3. resx files of custom modules
  4. custom.resx
  5. cms.resx

If there are duplicate strings with the same key in all five sources, the system uses the one stored in the database.

To change the priorities, you can add the following key to your web.config:

<add key="CMSUseSQLResourceManagerAsPrimary" value="false" />

When this key is added, the priorities are as follows:

  1. site specific resx files
  2. resx files of custom modules
  3. custom.resx
  4. cms.resx
  5. database
1 votesVote for this answer Mark as a Correct answer

Tom Troughton answered on May 27, 2016 09:39

@Jan - thank you for this info. I thought I'd tried this and it hadn't worked. Maybe I did something wrong. I'll try again.

@Brenden - when you have multiple developers adding resource strings to Localization of course these need to be synchronised between local development instances. Otherwise instead of seeing a translated label you only see the resource key.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 29, 2016 06:10

You are correct Nat. Keep in mind, if you're all connected to the same database then this isn't an issue as you'd all have access to the same localization data. If you're not connected to a shared database then I can see the use of your own .resx files.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.