/// <summary>
        /// Gets the node containing the translations.
        /// </summary>
        /// <param name="page">
        /// The node to get the translation node for.
        /// </param>
        /// <param name="culture">
        /// The culture (e.g., "es-mx") to get the translation node for.
        /// </param>
        /// <returns>
        /// The node containing the translations.
        /// </returns>
        public static IPublishedContent GetTranslationNode(IPublishedContent page,
                                                           string culture)
        {
            // Validate input.
            if (page == null)
            {
                return(null);
            }

            // Variables.
            var duration = TimeSpan.FromHours(1);
            var key      = new NodeAndCulture(page.Id, culture);
            var keys     = RhythmCacheHelper.PreviewCacheKeys;

            // Get the node ID from the cache.
            var translationNodeId = TranslationNodeIds.Get(key, nodeAndCulture =>
            {
                // Look for a translation folder.
                var folderNode = GetTranslationFolderForNode(page);

                // Look for a translation node under the folder.
                var translationNode = folderNode == null
                    ? null
                    : GetTranslationNodeFromFolder(folderNode, culture);
                return((translationNode ?? page).Id);
            }, duration, keys: keys);

            // Return translation node.
            var cache = UmbracoContext.Current.ContentCache;

            return(cache.GetById(translationNodeId));
        }
示例#2
0
 /// <summary>
 /// Compares this instance against another for equality.
 /// </summary>
 /// <param name="other">
 /// The other instance.
 /// </param>
 /// <returns>
 /// True, if the instances are equal; otherwise, false.
 /// </returns>
 public bool Equals(NodeAndCulture other)
 {
     if (other == null)
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(this.NodeId == other.NodeId && this.Culture == other.Culture);
 }