-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs multi language #1180
Merged
Merged
Docs multi language #1180
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
83679fb
implemented multi language on docs module basicly
yekalkan 77fef98
multi language on docs refactor
yekalkan 256e6eb
LanguageCode parameter added for DocumentAppService.GetResourceAsync
yekalkan 2153d4f
Update FileSystemDocumentStore.cs
yekalkan 3f5d12d
Update GithubDocumentStore_Tests.cs
yekalkan 6f5eb0f
docs configure redirects
yekalkan d7f375e
typo fix
yekalkan 9305b93
refactor
yekalkan d99efbc
MaxLanguageCodeLength moved to LanguageConsts
yekalkan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Caching.Distributed; | ||
using Microsoft.Extensions.Logging; | ||
|
@@ -15,27 +16,31 @@ public class DocumentAppService : ApplicationService, IDocumentAppService | |
private readonly IProjectRepository _projectRepository; | ||
private readonly IDocumentStoreFactory _documentStoreFactory; | ||
protected IDistributedCache<DocumentWithDetailsDto> DocumentCache { get; } | ||
protected IDistributedCache<LanguageConfig> LanguageCache { get; } | ||
protected IDistributedCache<DocumentResourceDto> ResourceCache { get; } | ||
|
||
public DocumentAppService( | ||
IProjectRepository projectRepository, | ||
IDocumentStoreFactory documentStoreFactory, | ||
IDistributedCache<DocumentWithDetailsDto> documentCache, | ||
IDistributedCache<LanguageConfig> languageCache, | ||
IDistributedCache<DocumentResourceDto> resourceCache) | ||
{ | ||
_projectRepository = projectRepository; | ||
_documentStoreFactory = documentStoreFactory; | ||
DocumentCache = documentCache; | ||
LanguageCache = languageCache; | ||
ResourceCache = resourceCache; | ||
} | ||
|
||
public virtual async Task<DocumentWithDetailsDto> GetAsync(GetDocumentInput input) | ||
{ | ||
var project = await _projectRepository.GetAsync(input.ProjectId); | ||
|
||
return await GetDocumentWithDetailsDto( | ||
return await GetDocument( | ||
project, | ||
input.Name, | ||
input.LanguageCode, | ||
input.Version | ||
); | ||
} | ||
|
@@ -44,9 +49,10 @@ public virtual async Task<DocumentWithDetailsDto> GetDefaultAsync(GetDefaultDocu | |
{ | ||
var project = await _projectRepository.GetAsync(input.ProjectId); | ||
|
||
return await GetDocumentWithDetailsDto( | ||
return await GetDocument( | ||
project, | ||
project.DefaultDocumentName, | ||
input.LanguageCode, | ||
input.Version | ||
); | ||
} | ||
|
@@ -55,22 +61,23 @@ public virtual async Task<DocumentWithDetailsDto> GetNavigationAsync(GetNavigati | |
{ | ||
var project = await _projectRepository.GetAsync(input.ProjectId); | ||
|
||
return await GetDocumentWithDetailsDto( | ||
return await GetDocument( | ||
project, | ||
project.NavigationDocumentName, | ||
input.LanguageCode, | ||
input.Version | ||
); | ||
} | ||
|
||
public async Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input) | ||
{ | ||
var project = await _projectRepository.GetAsync(input.ProjectId); | ||
var cacheKey = $"Resource@{project.ShortName}#{input.Name}#{input.Version}"; | ||
var cacheKey = $"Resource@{project.ShortName}#{input.LanguageCode}#{input.Name}#{input.Version}"; | ||
|
||
async Task<DocumentResourceDto> GetResourceAsync() | ||
{ | ||
var store = _documentStoreFactory.Create(project.DocumentStoreType); | ||
var documentResource = await store.GetResource(project, input.Name, input.Version); | ||
var documentResource = await store.GetResource(project, input.Name, input.LanguageCode, input.Version); | ||
|
||
return ObjectMapper.Map<DocumentResource, DocumentResourceDto>(documentResource); | ||
} | ||
|
@@ -92,20 +99,23 @@ async Task<DocumentResourceDto> GetResourceAsync() | |
); | ||
} | ||
|
||
protected virtual async Task<DocumentWithDetailsDto> GetDocumentWithDetailsDto( | ||
protected virtual async Task<DocumentWithDetailsDto> GetDocument( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename ro GetDocumentWithDetailsDtoAsync |
||
Project project, | ||
string documentName, | ||
string languageCode, | ||
string version) | ||
{ | ||
var cacheKey = $"Document@{project.ShortName}#{documentName}#{version}"; | ||
var cacheKey = $"Document@{project.ShortName}#{languageCode}#{documentName}#{version}"; | ||
|
||
async Task<DocumentWithDetailsDto> GetDocumentAsync() | ||
{ | ||
Logger.LogInformation($"Not found in the cache. Requesting {documentName} from the store..."); | ||
var store = _documentStoreFactory.Create(project.DocumentStoreType); | ||
var document = await store.GetDocumentAsync(project, documentName, version); | ||
var languages = await GetLanguageListAsync(store, project, version); | ||
var language = GetLanguageByCode(languages, languageCode); | ||
var document = await store.GetDocumentAsync(project, documentName, language.Code, version); | ||
Logger.LogInformation($"Document retrieved: {documentName}"); | ||
return CreateDocumentWithDetailsDto(project, document); | ||
return CreateDocumentWithDetailsDto(project, document, languages, language.Code); | ||
} | ||
|
||
if (Debugger.IsAttached) | ||
|
@@ -125,11 +135,43 @@ async Task<DocumentWithDetailsDto> GetDocumentAsync() | |
); | ||
} | ||
|
||
protected virtual DocumentWithDetailsDto CreateDocumentWithDetailsDto(Project project, Document document) | ||
protected virtual LanguageConfigElement GetLanguageByCode(LanguageConfig languageCodes, string languageCode) | ||
{ | ||
var language = languageCodes.Languages.FirstOrDefault(l => l.Code == languageCode); | ||
|
||
return language ?? languageCodes.Languages.Single(l => l.IsDefault); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throw a better exception if default language is not defined. |
||
} | ||
|
||
protected virtual async Task<LanguageConfig> GetLanguageListAsync(IDocumentStore store, Project project, string version) | ||
{ | ||
async Task<LanguageConfig> GetLanguagesAsync() | ||
{ | ||
return await store.GetLanguageListAsync(project, version); | ||
} | ||
|
||
return await LanguageCache.GetOrAddAsync( | ||
project.ShortName, | ||
GetLanguagesAsync, | ||
() => new DistributedCacheEntryOptions | ||
{ | ||
AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(24) | ||
} | ||
); | ||
} | ||
|
||
protected virtual DocumentWithDetailsDto CreateDocumentWithDetailsDto(Project project, Document document, LanguageConfig languages, string languageCode) | ||
{ | ||
var documentDto = ObjectMapper.Map<Document, DocumentWithDetailsDto>(document); | ||
documentDto.Project = ObjectMapper.Map<Project, ProjectDto>(project); | ||
documentDto.Contributors = ObjectMapper.Map<List<DocumentContributor>, List<DocumentContributorDto>>(document.Contributors); | ||
|
||
documentDto.Project.Languages = new Dictionary<string, string>(); | ||
foreach (var language in languages.Languages) | ||
{ | ||
documentDto.Project.Languages.Add(language.Code, language.DisplayName); | ||
} | ||
|
||
documentDto.CurrentLanguageCode = languageCode; | ||
return documentDto; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Language/LanguageConsts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
| ||
namespace Volo.Docs.Language | ||
{ | ||
public static class LanguageConsts | ||
{ | ||
public const int MaxLanguageCodeLength = 10; | ||
} | ||
} |
7 changes: 5 additions & 2 deletions
7
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Volo.Abp.Domain.Services; | ||
using Volo.Docs.GitHub.Documents; | ||
using Volo.Docs.Projects; | ||
|
||
namespace Volo.Docs.Documents | ||
{ | ||
public interface IDocumentStore : IDomainService | ||
{ | ||
Task<Document> GetDocumentAsync(Project project, string documentName, string version); | ||
Task<Document> GetDocumentAsync(Project project, string documentName, string languageCode, string version); | ||
|
||
Task<List<VersionInfo>> GetVersionsAsync(Project project); | ||
|
||
Task<DocumentResource> GetResource(Project project, string resourceName, string version); | ||
Task<DocumentResource> GetResource(Project project, string resourceName, string languageCode, string version); | ||
|
||
Task<LanguageConfig> GetLanguageListAsync(Project project, string version); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/LanguageConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Volo.Docs.Documents | ||
{ | ||
public class LanguageConfig | ||
{ | ||
public List<LanguageConfigElement> Languages { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/LanguageConfigElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Volo.Docs.Documents | ||
{ | ||
public class LanguageConfigElement | ||
{ | ||
public string DisplayName { get; set; } | ||
|
||
public string Code { get; set; } | ||
|
||
public bool IsDefault { get; set; } | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if input.LanguageCode is null?