From 490c32090bad7c1e849bd30f1c25f82e9da8002c Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Tue, 12 Mar 2024 11:41:37 -0500 Subject: [PATCH] Restore updates to LocaleFreshness --- .../Documentarian.MicrosoftDocs/.DevX.jsonc | 8 +- .../reference/cmdlets/Get-LocaleFreshness.md | 76 ++++++++++--------- .../Source/Public/Classes/.LoadOrder.jsonc | 5 ++ .../Source/Public/Classes/LearnLocales.psm1 | 20 +++++ .../Public/Functions/Get-LocaleFreshness.ps1 | 22 +++--- 5 files changed, 82 insertions(+), 49 deletions(-) create mode 100644 Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Classes/LearnLocales.psm1 diff --git a/Projects/Modules/Documentarian.MicrosoftDocs/.DevX.jsonc b/Projects/Modules/Documentarian.MicrosoftDocs/.DevX.jsonc index ad6b2b1..7c30fa3 100644 --- a/Projects/Modules/Documentarian.MicrosoftDocs/.DevX.jsonc +++ b/Projects/Modules/Documentarian.MicrosoftDocs/.DevX.jsonc @@ -1,9 +1,9 @@ { "ManifestData": { "Guid": "a054ec31-cb69-4a4b-b66b-39d25e909615", - "ModuleVersion": "0.0.2", + "ModuleVersion": "0.0.3", "RootModule": "Documentarian.MicrosoftDocs.psm1", - "ScriptsToProcess": "Init.ps1", + "ScriptsToProcess": "", "VariablesToExport": "*", "Author": "PowerShell Docs Team", "CompanyName": "Microsoft", @@ -29,8 +29,8 @@ "ModuleLicenseNotice": "Licensed under the MIT License.", "ModuleLineEnding": "\n", "ModuleName": "Documentarian.MicrosoftDocs", - "ModuleVersion": "0.0.1", + "ModuleVersion": "0.0.3", "OutputFolderPath": "./[[ManifestData.ModuleVersion]]", "SourceFolderPath": "./Source", - "SourceInitScriptPath": "./Source/Init.ps1" + // "SourceInitScriptPath": "./Source/Init.ps1" } diff --git a/Projects/Modules/Documentarian.MicrosoftDocs/Documentation/reference/cmdlets/Get-LocaleFreshness.md b/Projects/Modules/Documentarian.MicrosoftDocs/Documentation/reference/cmdlets/Get-LocaleFreshness.md index 26d2836..9065159 100644 --- a/Projects/Modules/Documentarian.MicrosoftDocs/Documentation/reference/cmdlets/Get-LocaleFreshness.md +++ b/Projects/Modules/Documentarian.MicrosoftDocs/Documentation/reference/cmdlets/Get-LocaleFreshness.md @@ -15,7 +15,7 @@ Gets the `ms.date` metadata information of a Docs article for every locale. ## SYNTAX ``` -Get-LocaleFreshness [-Uri] [[-Locales] ] [] +Get-LocaleFreshness [-Uri] [[-Locale] ] [] ``` ## DESCRIPTION @@ -24,6 +24,8 @@ Gets the `ms.date` metadata information of a Docs article for every locale. The locale information and the translation method. This is useful to see that the localization process has picked up the latest changes made to the English version of the article. +For comparison, the output of the cmdlet always includes the English version of the article. + ## EXAMPLES ### Example 1 - Get the freshness data for an article @@ -80,8 +82,9 @@ Get-LocaleFreshness $url pt-br, pt-pt ```Output locpath locale ms.contentlocale ms.translationtype ms.date loc_version updated_at ------- ------ ---------------- ------------------ ------- ----------- ---------- -pt-br pt-br pt-br HT 05/31/2022 2022-07-18T20:00:40.4523397Z 2022-08-17 10:12 PM -pt-pt pt-pt pt-pt MT 05/31/2022 2022-07-18T20:00:40.4523397Z 2022-08-17 10:12 PM +en-us en-us 01/09/2023 2023-09-05 09:55 PM +pt-br pt-br pt-br HT 01/09/2023 2023-09-26T22:04:42.7240190Z 2023-10-13 11:23 PM +pt-pt pt-pt pt-pt MT 01/09/2023 2023-10-26T21:59:59.7444562Z 2023-10-26 11:59 PM ``` ### Example 3 - Get the full freshness data for an article for select languages @@ -94,48 +97,51 @@ Get-LocaleFreshness $url pt-br | Format-List -Property * ``` ```Output +locpath : en-us +locale : en-us +ms.contentlocale : +ms.translationtype : +ms.date : 01/09/2023 +loc_version : +updated_at : 2023-09-05 09:55 PM +loc_source_id : +loc_file_id : +original_content_git_url : https://github.com/MicrosoftDocs/PowerShell-Docs/blob/live/reference/docs-conceptual/install/In + stalling-PowerShell-on-Linux.md + locpath : pt-br locale : pt-br ms.contentlocale : pt-br ms.translationtype : HT -ms.date : 05/31/2022 -loc_version : 2022-07-18T20:00:40.4523397Z -updated_at : 2022-08-17 10:12 PM +ms.date : 01/09/2023 +loc_version : 2023-09-26T22:04:42.7240190Z +updated_at : 2023-10-13 11:23 PM loc_source_id : Github-44411511#live -loc_file_id : Github-44411511.live.PowerShell.PowerShell_PowerShell-docs_reference.docs-conceptual/install - /Installing-PowerShell-on-Linux.md -original_content_git_url : https://github.com/MicrosoftDocs/PowerShell-Docs/blob/live/reference/docs-conceptual/install - /Installing-PowerShell-on-Linux.md +loc_file_id : Github-44411511.live.PowerShell.PowerShell_PowerShell-docs_reference.docs-conceptual/install/In + stalling-PowerShell-on-Linux.md +original_content_git_url : https://github.com/MicrosoftDocs/PowerShell-Docs/blob/live/reference/docs-conceptual/install/In + stalling-PowerShell-on-Linux.md ``` ## PARAMETERS -### -Locales +### -Locale An array of one or more locale strings. The parameter default defaults to the following array of values: -- `en-us` -- `cs-cz` -- `de-de` -- `es-es` -- `fr-fr` -- `hu-hu` -- `id-id` -- `it-it` -- `ja-jp` -- `ko-kr` -- `nl-nl` -- `pl-pl` -- `pt-br` -- `pt-pt` -- `ru-ru` -- `sv-se` -- `tr-tr` -- `zh-cn` -- `zh-tw` - -The value can be any valid locale identifier string. +- `ar-sa`, `cs-cz`, `de-de`, `en-us`, `es-es`, `fr-fr`, `hu-hu`, `id-id`, `it-it`, `ja-jp`, `ko-kr`, + `nl-nl`, `pl-pl`, `pt-br`, `pt-pt`, `ru-ru`, `sv-se`, `tr-tr`, `zh-cn`, `zh-tw` + +The value can be any of the locales supported by the docs platform: + +- `ar-sa`, `bg-bg`, `bs-latn-ba`, `ca-es`, `cs-cz`, `da-dk`, `de-at`, `de-ch`, `de-de`, `el-gr`, + `en-au`, `en-ca`, `en-gb`, `en-ie`, `en-in`, `en-my`, `en-nz`, `en-sg`, `en-us`, `en-za`, `es-es`, + `es-mx`, `et-ee`, `eu-es`, `fi-fi`, `fil-ph`, `fr-be`, `fr-ca`, `fr-ch`, `fr-fr`, `ga-ie`, + `gl-es`, `he-il`, `hi-in`, `hr-hr`, `hu-hu`, `id-id`, `is-is`, `it-ch`, `it-it`, `ja-jp`, `ka-ge`, + `kk-kz`, `ko-kr`, `lb-lu`, `lt-lt`, `lv-lv`, `ms-my`, `mt-mt`, `nb-no`, `nl-be`, `nl-nl`, `pl-pl`, + `pt-br`, `pt-pt`, `ro-ro`, `ru-ru`, `sk-sk`, `sl-si`, `sr-cyrl-rs`, `sr-latn-rs`, `sv-se`, + `th-th`, `tr-tr`, `uk-ua`, `vi-vn`, `zh-cn`, `zh-hk`, `zh-tw` ```yaml Type: System.String[] @@ -144,14 +150,14 @@ Aliases: Required: False Position: 1 -Default value: en-us, cs-cz, de-de, es-es, fr-fr, hu-hu, id-id, it-it, ja-jp, ko-kr, nl-nl, pl-pl, pt-br, pt-pt, ru-ru, sv-se, tr-tr, zh-cn, zh-tw +Default value: 'ar-sa', 'en-us', 'cs-cz', 'de-de', 'es-es', 'fr-fr', 'hu-hu', 'id-id', 'it-it', 'ja-jp', 'ko-kr', 'nl-nl', 'pl-pl', 'pt-br', 'pt-pt', 'ru-ru', 'sv-se', 'tr-tr', 'zh-cn', 'zh-tw' Accept pipeline input: False Accept wildcard characters: False ``` ### -Uri -The URL to the article being inspected. The URL must contain a locale. +The URL to the article being inspected. The URL must contain a supported locale. ```yaml Type: System.Uri @@ -188,4 +194,6 @@ tags are set by the build system when the article is published. ## NOTES +This cmdlet depends on the `Get-HtmlMetaTags` cmdlet. + ## RELATED LINKS diff --git a/Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Classes/.LoadOrder.jsonc b/Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Classes/.LoadOrder.jsonc index fb44a7a..836e94b 100644 --- a/Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Classes/.LoadOrder.jsonc +++ b/Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Classes/.LoadOrder.jsonc @@ -6,4 +6,9 @@ // "IgnoreForBuild": false, // "IgnoreForTest": false // } + { + "Name": "LearnLocales", + "IgnoreForBuild": false, + "IgnoreForTest": true + } ] diff --git a/Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Classes/LearnLocales.psm1 b/Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Classes/LearnLocales.psm1 new file mode 100644 index 0000000..02e004e --- /dev/null +++ b/Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Classes/LearnLocales.psm1 @@ -0,0 +1,20 @@ +class LearnLocales { + + ## This list of locales is based on the language selection page on the Learn platform. + + static [string[]]$SupportedLocales = 'ar-sa', 'bg-bg', 'bs-latn-ba', 'ca-es', 'cs-cz', 'da-dk', + 'de-at', 'de-ch', 'de-de', 'el-gr', 'en-au', 'en-ca', 'en-gb', 'en-ie', 'en-in', 'en-my', + 'en-nz', 'en-sg', 'en-us', 'en-za', 'es-es', 'es-mx', 'et-ee', 'eu-es', 'fi-fi', 'fil-ph', + 'fr-be', 'fr-ca', 'fr-ch', 'fr-fr', 'ga-ie', 'gl-es', 'he-il', 'hi-in', 'hr-hr', 'hu-hu', + 'id-id', 'is-is', 'it-ch', 'it-it', 'ja-jp', 'ka-ge', 'kk-kz', 'ko-kr', 'lb-lu', 'lt-lt', + 'lv-lv', 'ms-my', 'mt-mt', 'nb-no', 'nl-be', 'nl-nl', 'pl-pl', 'pt-br', 'pt-pt', 'ro-ro', + 'ru-ru', 'sk-sk', 'sl-si', 'sr-cyrl-rs', 'sr-latn-rs', 'sv-se', 'th-th', 'tr-tr', 'uk-ua', + 'vi-vn', 'zh-cn', 'zh-hk', 'zh-tw' + + ## Most docs are trnaslated into a subset of 19 locales. + + static [string[]]$CommonLocales = 'ar-sa', 'en-us', 'cs-cz', 'de-de', 'es-es', 'fr-fr', 'hu-hu', + 'id-id', 'it-it', 'ja-jp', 'ko-kr', 'nl-nl', 'pl-pl', 'pt-br', 'pt-pt', 'ru-ru', 'sv-se', + 'tr-tr', 'zh-cn', 'zh-tw' + +} \ No newline at end of file diff --git a/Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Functions/Get-LocaleFreshness.ps1 b/Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Functions/Get-LocaleFreshness.ps1 index f0b6591..1108e3f 100644 --- a/Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Functions/Get-LocaleFreshness.ps1 +++ b/Projects/Modules/Documentarian.MicrosoftDocs/Source/Public/Functions/Get-LocaleFreshness.ps1 @@ -1,6 +1,8 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +using module ..\Classes\LearnLocales.psm1 + function Get-LocaleFreshness { [CmdletBinding()] @@ -10,23 +12,21 @@ function Get-LocaleFreshness { [uri]$Uri, [Parameter(Position = 1)] - [ValidatePattern('[a-z]{2}-[a-z]{2}')] - [string[]]$Locales = ( - 'en-us', 'cs-cz', 'de-de', 'es-es', 'fr-fr', 'hu-hu', 'id-id', 'it-it', - 'ja-jp', 'ko-kr', 'nl-nl', 'pl-pl', 'pt-br', 'pt-pt', 'ru-ru', 'sv-se', - 'tr-tr', 'zh-cn', 'zh-tw' - ) + [ValidateScript({$_ -in [LearnLocales]::SupportedLocales})] + [string[]]$Locale = [LearnLocales]::CommonLocales ) - $locale = $uri.Segments[1].Trim('/') - if ($locale -notmatch '[a-z]{2}-[a-z]{2}') { - Write-Error "URL does not contain a valid locale: $locale" + $localeInUrl = $uri.Segments[1].Trim('/') + if ($localeInUrl -notin [LearnLocales]::SupportedLocales) { + Write-Error "URL does not contain a supported locale: $localeInUrl" return } else { + $url = $uri.OriginalString - $Locales | ForEach-Object { + if ($Locale -notcontains 'en-us') { $Locale += 'en-us' } + $Locale | ForEach-Object { $locPath = $_ - $result = Get-HtmlMetaTags ($url -replace $locale, $locPath) | + $result = Get-HtmlMetaTags ($url -replace $localeInUrl, $locPath) | Select-Object @{n = 'locpath'; e = { $locPath } }, locale, 'ms.contentlocale', 'ms.translationtype', 'ms.date', 'loc_version', 'updated_at', 'loc_source_id', 'loc_file_id', 'original_content_git_url'